输入多行字符判断是否是回文 求教

fx397993401 2009-08-02 11:04:03
Bart’s Palindromes
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 77, Accepted users: 61
Problem 11498 : No special judgement
Problem description
Bart is trying to come up with funny palindromes, and decides to write a program to check whether a string is a palindrome. The program should read strings on separate lines and determine whether the entire string is a palindrome. The program should only check letters (i.e., a-z, A-Z), and ignore all blanks, numbers, and punctuation.




Input
The input will consist of a sequence of lines, each of which should be tested separately. Each line will be no greater than 100 characters long. A blank line signals the end of input.


Output
After each line, the program should print on a separate line, either YES (if the input was a palindrome) or NO (otherwise).


Sample Input
radar
rAd. Ar
radiar
able was I ere I saw elba!
b
bb
ab
aabaa
aabbaa
aab2aa
aabaaa
This is a palindrome
radar is a palindrome
a man, a plan, a canal, panama!
a bell was eye, ear I saw elbow
go hang a salami, bub, i’m a lasagna hog!!

Sample Output
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
NO
YES

# include<stdio.h>
# include<stdlib.h>
# include<string.h>
# include<ctype.h>
int main()
{

char *str1,str[1000] = {NULL};
char *str2;
char c;
int i,j;
//freopen("outt.txt","w",stdout);
while(1)
{
str2 = (char*)calloc(1000,sizeof(char));
str1 = (char*)calloc(1000,sizeof(char));
i =0;
while((c = getchar())!= '\n')
{
if(isalpha(c))
str1[i++] = c;
if(c == EOF)
return 1;
}
str1[i] = '\0';
memcpy(str2,str1,strlen(str1));
strrev(str1);
if(strcmp(str1,str2))
printf("NO\n");
else
printf("YES\n");

free(str1);
str1 = NULL;
free(str2);
str2 = NULL;
}

return 0;
}


不知道我的程序错在哪 提交的时候 runtime 错误 是不是结束没有处理好文件的结束符 题目地址 http://acm.hnu.cn:8080/online/?action=problem&type=show&id=11498&courseid=131
...全文
83 点赞 收藏 6
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fx397993401 2009-08-02
[Quote=引用 2 楼 ahjoe 的回复:]
百度不是号称中国公司吗,怎么出个鸟题目还用英文,挺能装的!
[/Quote]

不是百度的 是湖南大学ACM网站上的
回复
ahjoe 2009-08-02
百度不是号称中国公司吗,怎么出个鸟题目还用英文,挺能装的!
回复
fx397993401 2009-08-02
The program should only check letters (i.e., a-z, A-Z), 就是说只处理大小字母 忽略其他字符
回复
fx397993401 2009-08-02
[Quote=引用 5 楼 vshuang 的回复:]
Input
The input will consist of a sequence of lines, each of which should be tested separately. Each line will be no greater than 100 characters long. A blank line signals the end of input.
楼主没有看清楚题目吧?


引用楼主 fx397993401 的帖子:
Bart’s Palindromes
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 77, Accepted users: 61
Probl…
[/Quote]

这个问题 后来发现了 用了这个

#include<iostream>
int main(int argc, char* argv[])
{
char str1[101] = {NULL},str[1001] = {NULL};
char str2[101] = {NULL};;
int i,j;
while(gets(str1)!=NULL)
{
if(str1[0]=='\0')
return 0;
for(i = 0,j=0;str1[i]!='\0';i ++)
if(isalpha(str1[i]))
str1[j++] = str1[i];
str1[j] = '\0';
memcpy(str2,str1,strlen(str1)+1);
strrev(str1);
if(!strcmp(str1,str2))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
回复
Input
The input will consist of a sequence of lines, each of which should be tested separately. Each line will be no greater than 100 characters long. A blank line signals the end of input.
楼主没有看清楚题目吧?

[Quote=引用楼主 fx397993401 的帖子:]
Bart’s Palindromes
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 77, Accepted users: 61
Problem 11498 : No special judgement
Problem description
Bart is trying to come up with funny palindromes, and decides to write a program to check whether a string is a palindrome. The program should read strings on separate lines and determine whethe…
[/Quote]
回复
fx397993401 2009-08-02
汗颜 这个在本地运行没错 只是上传到服务器判题的时候错误 我的编译器是 vc 服务器的是GNU c
回复
发动态
发帖子
数据结构与算法
创建于2007-08-27

3.2w+

社区成员

数据结构与算法相关内容讨论专区
申请成为版主
社区公告
暂无公告