| Palindromes |
| Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB |
| Total submit users: 184, Accepted users: 175 |
| Problem 10136 : No special judgement |
| Problem description |
| Background: Palindromes are strings that read the same both forwards and backwards. `Eye' is one such example (ignoring case). In this problem, you get to write a program to determine if a given word is a palindrome or not. |
| Input |
| Each line of input contains one word with no embedded spaces. Each word will have only alphabetic characters (either upper or lower case). |
| Output |
| For each line of input, output either `yes' if the word is a palindrome or `no' otherwise. Don't print the quotes. Case should be ignored when checking the words. |
| Sample Input |
eyE laLAlal Foof foobar |
| Sample Output |
yes yes yes no |
| Problem Source |
| UD Contest |
#include <stdio.h>
#define YES 1
#define NO 0
main()
{
int flag;
char s[1000];
int i,j,n;
while( scanf("%s",s) > 0 ){
n = 0;
while( s[n] != '/0' ) n++;
for( i = 0 ; (i+1) <= (n/2) ; i++ ){
if( tolower(s[i])!= tolower(s[n-1-i]) ){flag=NO;break;}
else flag=YES;
}
if(flag==NO)printf("no/n");
else printf("yes/n");
}
return 0;
}
#define YES 1
#define NO 0
main()
{
int flag;
char s[1000];
int i,j,n;
while( scanf("%s",s) > 0 ){
n = 0;
while( s[n] != '/0' ) n++;
for( i = 0 ; (i+1) <= (n/2) ; i++ ){
if( tolower(s[i])!= tolower(s[n-1-i]) ){flag=NO;break;}
else flag=YES;
}
if(flag==NO)printf("no/n");
else printf("yes/n");
}
return 0;
}
本文介绍了一个简单的程序设计问题:如何判断一个字符串是否为回文。通过忽略大小写差异,该程序能够正确判断输入的单词是否正读反读都相同。
131

被折叠的 条评论
为什么被折叠?



