南邮 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");
		}
	}
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值