南邮 OJ 1384 Palindromes

Palindromes

时间限制(普通/Java) :  1000 MS/ 3000 MS          运行内存限制 : 81920 KByte
总提交 : 69            测试通过 : 40 

比赛描述

Write a program that determines if each input string is a palindrome. A palindrome is a

string that reads exactly the same in both forward and reverse directions. For something

to be considered a palindrome, it must be at least 1 character long. For the purposes of

your program, ignore any characters that are not letters, as well as spaces when

determining if a string is a palindrome.




输入

The first line of input contains an integer N that indicates the number of test strings to

follow. On each subsequent line there will be a single test string. Here is a sample:


输出

For each test string, output "yes" if the string was a palindrome, and "no" if it was not a

palindrome. Remember: Ignore any characters that are not letters, as well as spaces.


样例输入

5
able ##was I, e****re I s.aw $Elba
this is not a palindrome
A man, a plan, a canal, Panama
another random string
Sator Arepo Tenet Opera Rotas

样例输出

yes
no
yes
no
yes

提示

undefined

题目来源

Internet



#include<iostream>
#define MAX_N 1000

char c1[MAX_N],c2[MAX_N];

int main(){
	int N,i,j,len;
	scanf("%d",&N);
	getchar();
	while(N--){
		scanf("%[^\n]",c1);
		getchar();
		len = (int)strlen(c1);
		for(i=j=0;i<len;i++){
			if(c1[i]>='a' && c1[i]<='z'){
				c2[j++] = c1[i];
			}else if(c1[i]>='A' && c1[i]<='Z'){
				c2[j++] = c1[i]+'a'-'A';
			}
		}
		len = j;
		for(i=0;(i<<1)<len;i++){
			if(c2[i]!=c2[len-1-i]){
				break;
			}
		}
		if((i<<1)<len){
			printf("no\n");
		}else{
			printf("yes\n");
		}
	}
}






你可能感兴趣的:(ACM,Palindromes,南邮OJ)