描述
Give the definition of a new word:
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.
We want you to write a program that can check whether a given input is palindrome or not. The input will only contain English alphabets and digits. Remember, in this task, uppercase and lowercase letter count as same.
输入
Input starts with an integer T (≤ 1000), denoting the number of test cases. Each test case will have one line containing the text to test. You can assume that each input text will be less than 100 characters in length.
输出
For each test case, print either “Yes” (without quotes) or “No” (without quotes). If the input text is palindrome then print “Yes”, otherwise print “No”
输入样例 1
3
abababa
ababab
1EYE1
输出样例 1
Yes
No
Yes
来源
NEEPU_ACM_2017_训练赛(2)
代码
#include <cstdio>
#include <cstring>
using namespace std;
void judge(char a[]){
int i = 0, j = strlen(a) - 1;
for(int k = 0; k <= j; k++){
if(a[k] >= 65 && a[k] <= 90) a[k] += 32;
}
while(i < j){
if(a[i] != a[j]) break;
i++;
j--;
}
if(i >= j) printf("Yes\n");
else printf("No\n");
}
int main(){
int n;
char a[101];
scanf("%d", &n);
while(n--){
scanf("%s", a);
judge(a);
}
return 0;
}