王道oj/problem10


地址:http://oj.lgwenda.com/problem/10

思路:首先创建字符串赋初值,其次用gets()输入字符串【fgets()相对于gets()会多识别"\n",fgets(c,sizeof(c),stdin);】

           紧接着用循环倒置字符串

   最后根据题目要求用条件语句输出值

代码:

#define _CRT_SECURE_NO_WARNINGS
#include
#include
int main()
{
char a[100]={0}, b[100]={0};
gets(a);
int c = strlen(a);
for (int i = 0; i < c; i++)
{
b[c - i - 1] = a[i];
}
int result = strcmp(a, b);
if (result < 0)printf("%d\n", -1);
else if (result == 0)printf("%d\n", 0);
else printf("%d\n", 1);
//puts(b);
return 0;
}

相关