读取一个字符串,字符串可能含有空格,将字符串逆转
原来的字符串与逆转后字符串比较相同,输出0,
原字符串小于逆转后字符串输出-1,
大于逆转后字符串输出1。
例如输入 hello,逆转后的字符串为 olleh,因为hello 小于 olleh,所以输出-1
Sample Input 1
helloSample Output 1
-1
#include <stdio.h>
#include <string.h>
int main(){
char str[20];
char reStr[20];
int j=0;
gets(str);
int len=strlen(str);
for (int i = len-1; i >=0 ; i--) {//将str数组逆置
reStr[j++]=str[i];
}
int cmpResult=strcmp(str,reStr);
if(cmpResult<0){
printf("%d\n",-1);
}
else if(cmpResult>0){
printf("%d\n", 1);
}
else{
printf("%d\n", 0);
}
}