首页 > 其他 > 详细

Third practice 4

时间:2020-05-18 16:07:11      阅读:40      评论:0      收藏:0      [点我收藏+]

Third practice 4

任务描述

编写函数reverse(char *s)的倒序递归程序,使字符串s倒序。

测试输入:输入一个字符串:zxc; 预期输出: 原字符串为:zxc 倒序反转后为:cxz

测试输入:输入一个字符串:machine@##; 预期输出: 原字符串为:machine@## 倒序反转后为:##@enihcam

源代码

#include <iostream>
#include <string>
using namespace std;
void reverse(char *s, char *t)
{
	
}
void reverse(char *s)
{
	char *p1,*p2;
	char temp;
	p1 = p2 = s;
	while(*p2!=‘\0‘){
		p2++;
	}
	p2--;

	while(p1<p2){
		temp = *p1;
		*p1 = *p2;
		*p2 = temp;
		p1++;
		p2--;
	}
}
int main(){
	char a[50];
	cout<<"输入一个字符串:";
	cin>>a;
	cout<<a<<endl;
	cout<<"原字符串为:"<<a<<endl;

	reverse(a);
	cout<<"倒序反转后为:"<<a;
	return 0;
}

Third practice 4

原文:https://www.cnblogs.com/lightice/p/12910891.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!