41A題目網址
題目解析
1.輸入一個字符串,如果第二行是倒序輸入這個字符串的,就輸出YES,否則輸出NO
舉例:
輸入:
abb
aba
輸出:
NO
2.倒序輸出時,使用int j=strlen(t)-1;,因為strlen()是計算字符個數,而字符串是從0開始,最后一位是字符串長度減一
3.在接收第二個字符串輸入時,因為有enter鍵,所以使用getchar()去接收
即:
scanf("%s",s);
getchar();
scanf("%s",t);
代碼
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{ char s[100]={'0'};char t[100]={'0'};scanf("%s",s);getchar();scanf("%s",t);int j=strlen(t)-1,flag=0;for(int i=0;i<strlen(s);i++){if(s[i]==t[j--]){flag=1;}else {flag=0;break;}}if(flag){printf("YES");}else{printf("NO");}getchar();system("pause");return 0;
}