杭电oj —— 2029

import java.util.Scanner;

public class HDU_oj2029 {
	/*
	 * “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”.
	 */
	public static void main(String[] args) {
		Scanner sn = new Scanner(System.in);
		while (sn.hasNext()) {
			int n = Integer.parseInt(sn.nextLine());
			for (int i = 0; i < n; i++) {
				String s = sn.nextLine();
				boolean flag = true;
				for (int k = 0,j = s.length()-1; k< s.length()/2; k++, j--) {
					if (s.charAt(k) != s.charAt(j)) {  //头尾比较
						flag = false;
						break;
					}
				}

				if (flag) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
		sn.close();
	}
}

猜你喜欢

转载自blog.csdn.net/LiLi_code/article/details/87875395