NOJ Palindromes
来源:互联网 发布:手机会议录音软件 编辑:程序博客网 时间:2024/06/05 16:54
Palindromes
总提交 : 65 测试通过 : 36
题目描述
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
分析:判断输入的字符串是否回文,仅考虑字符串中的字母,我们可以将输入字符串中的字母存在另一个数组里进行判断。
实现代码:
<span style="font-size:12px;">#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int T;int main(){ // freopen("data.in","r",stdin); scanf("%d",&T); getchar(); lp:while(T--) { char a[200000],b[200000]; a[0]='\0'; b[0]='\0'; gets(a); int cnt=0; for(int i=0;i<strlen(a);i++) { if((a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z')) b[cnt++]=a[i]; } for(int i=0,j=cnt-1;i<=j;i++,j--) { if(b[i]!=b[j]&&b[i]!=b[j]+32&&b[i]+32!=b[j]) { printf("no\n"); goto lp; } } printf("yes\n"); }}</span>
- NOJ Palindromes
- Noj
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- 黑马程序员-JAVA.net-网络工具类粗解
- struts2小技巧总结
- strcpy与memcpy
- 第一次大作业分析【界面篇】
- MySQL · 答疑释惑 · GTID下auto_position=0时数据不一致
- NOJ Palindromes
- apache hive 0.14 beeline 使用注意事项
- 一个小错误
- Struts1.x系列教程(13):国际化
- ActionBar+DrawerLayout实现网易新闻客户端首页
- WebApi中实现Cors访问
- MySQL · 捉虫动态 · 删被引用索引导致crash
- IOS retain copy assign alloc atomic nonatomic 内存管理和getter setter方法!
- 7 Python Regular Expressions Examples – Re Match Search FindAll