题解 | #字符逆序#
字符逆序
http://www.nowcoder.com/practice/cc57022cb4194697ac30bcb566aeb47b
就逆序输出,刚开始用scanf(“%s”)函数踩了个坑,记得用gets()。不然就得用scanf(“%c”)依次单个读入数据然后存到一个字符数组中,空格符才不会出问题。
#include<stdio.h>
#include<string.h>
int main(){
char str[10001]={'\0'};
while(gets(str)){ //注:这里不能使用scanf("%d",str)函数,含空格字符串会被视为多组输入。
int len=strlen(str);
for(int i=len-1;i>=0;i--){
printf("%c",str[i]);
}printf("\n");
}
}