Palindromes _easy version

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33310    Accepted Submission(s):
20276

Problem Description
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。
 
Input
输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串。
 
Output
如果一个字符串是回文串,则输出"yes",否则输出"no".
 
Sample Input
4
level
abcde
noon
haha
 
Sample Output
yes
no
yes
no

import java.util.*;
class Main{
public static void main(String args[])
{Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
String str;
cin.nextLine();
while(n-->0)
{ str=cin.next();
char [] a=str.toCharArray();
int flag=0;
for(int i=0;i<=str.length()/2;i++)
if(a[i]!=a[(str.length()-1)-i])
{flag=1;
break;
}
if(flag==1)
System.out.println("no");
if(flag==0)
System.out.println("yes");
}
}
}

、、、、、、、、、、、、、、、、、、、、、、、、

import java.util.*;
class Main{
public static void main(String args[])
{Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
while(n-->0)
{ String str=cin.next();
char [] a=str.toCharArray();
int flag=0;
for(int i=0;i<=str.length()/2;i++)
if(a[i]!=a[(str.length()-1)-i])
{flag=1;
break;
}
if(flag==1)
System.out.println("no");
if(flag==0)
System.out.println("yes");
}
}
}

以上的两种都是可以的。开始错了是把str.length();写成了a.length;小细节要多注意;

HDU2029JAVA的更多相关文章

随机推荐

  1. 解决iOS应用内购买报错:invalidProductIdentifiers

    当写完IAP业务过程后,点击测试却发现没有返回成功的商品Id,反而返回了无效的商品:response.invalidProductIdentifiers 这种情况下考虑以下因素: 创建的App ID是 ...

  2. 转:在Eclipse中进行C/C++开发的配置方法(20140721最新版)

    http://blog.csdn.net/baimafujinji/article/details/38026421 Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其本身而言,它 ...

  3. Spring factorybean

    自定义FactoryBean 需要实现FactoryBean接口 通过FacotryBean来配置bean的实例. class: 指向FactoryBean的全类名 property:配置Factor ...

  4. Perl脚本学习经验(三)--Perl中ftp的使用

    使用use Net::FTP;Demo:    my $Server = '192.168.1.1';    my $User = 'admin';    my $Password = 'admin' ...

  5. bzoj2754

    看到这道题一开始想到的是后缀数组+二分+rmq 类似bzoj3172 问每个串i在合并后的串出现了多少次 等价于有多少个后缀j,使得LCP(i,j)>=length(s[i]) 但是想想又不对, ...

  6. ☀【JS组织】pageA_init, pageB_init

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  7. 【Android 复习】 : Activity之间传递数据的几种方式

    在Android开发中,我们通常需要在不同的Activity之间传递数据,下面我们就来总结一下在Activity之间数据传递的几种方式. 1. 使用Intent来传递数据 Intent表示意图,很多时 ...

  8. 常用开源GIS项目

    常用开源GIS项目     常用开源桌面GIS软件 QGIS 始于2002年5月,算得上是开源GIS平台中的后起之秀.界面友好,分析功能可与GRASS GIS相媲美.主页:http://www.qgi ...

  9. jQuery获取属性之自己遇到的问题

    刚开始是这种写法  用的 attr  结果获取不到 if($("#reg_username_span").attr("display") == 'block') ...

  10. 如何解决PHP生成UTF-8编码的CSV文件用Excel打开乱码的问题

    为了识别 Unicode 文件,Microsoft 建议所有的 Unicode 文件应该以 ZERO WIDTH NOBREAK SPACE字符开头.这作为一个”特征符”或”字节顺序标记(byte-o ...