64,680
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
void revstr(char *s);
int main()
{
char a[81];
gets(a);
revstr(a);
cout<<endl;
return 0;
}
void revstr(char *s)
{
int len=strlen(s)/2;;
char *p,c,*q;
q=s;
p=s+strlen(s)-1;//指向数组末的指针
if(!s)
return;
cout<<len<<endl;
for(int i=0;i<len;++i)
{
c=*s;
*s++=*p;
*p--=c;
}
s=q;
while(*s!='\0')//输出逆置后的字符串
{
cout<<*s++;
}
}
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
void main()
{
void revstr(char *s);
char a[81];
gets(a);
char *s;//定义一个指向数组开头的指针
s=a;
revstr(s);
}
void revstr(char *s)
{
char *p,c,*q;
q=s;
p=s+strlen(s)-1;//指向数组末的指针
while(s==NULL)
{
return;
}
do//逆置的实现
{
c=*s;
*(s++)=*p;
*(p--)=c;
}while(*s<*p);
while(*q!='\0')//输出逆置后的字符串
{
cout<<*(q++);
}
}