Problem Description

Write a program to determine whether a word is a palindrome. A palindrome is a sequence of characters that is identical to the string when the characters are placed in reverse order. For example, the following strings are palindromes: “ABCCBA”, “A”, and “AMA”. The following strings are not palindromes: “HELLO”, “ABAB” and “PPA”.

Input

The input file will consist of up to 100 lines, where each line contains at least 1 and at most 52 characters. Your program should stop processing the input when the input string equals “STOP”. You may assume that input file consists of exclusively uppercase letters; no lowercase letters, punctuation marks, digits, or whitespace will be included within each word.

Output

A single line of output should be generated for each string. The line should include “#”, followed by the problem number, followed by a colon and a space, followed by the string “YES” or “NO”.

Sample Input

ABCCBA

A

HELLO

ABAB

AMA

ABAB

PPA

STOP

Sample Output

#1: YES
#2: YES
#3: NO
#4: NO
#5: YES
#6: NO
#7: NO

就是简单的判断回文串的问题,遇到STOP结束程序。

import java.util.Scanner;

/**
* @author 陈浩翔
* 2016-6-5
*/
public class Main{ public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t =1;
while(sc.hasNext()){
String str =sc.next();
if("STOP".equals(str)){
return;
}
System.out.print("#"+(t++)+": ");
boolean isProgram = true;
for(int i=0,j=str.length()-1;i<j;i++,j--){
if(str.charAt(i)!=str.charAt(j)){
isProgram=false;
break;
}
}
if(isProgram){
System.out.println("YES");
}else{
System.out.println("NO");
} }
}
}

HDOJ/HDU 2163 Palindromes(判断回文串~)的更多相关文章

  1. [leetcode]125. Valid Palindrome判断回文串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  2. UVA 11584 Partitioning by Palindromes 划分回文串 (Manacher算法)

    d[i]表示前面i个字符划分成的最小回文串个数, 转移:当第i字符加进来和前面区间j构成回文串,那么d[i] = d[j]+1. 要判断前面的字符j+1到i是不是回文串,可以用Manacher算法预处 ...

  3. hdu 3613 扩展kmp+回文串

    题目大意:给个字符串S,要把S分成两段T1,T2,每个字母都有一个对应的价值,如果T1,T2是回文串(从左往右或者从右往左读,都一样),那么他们就会有一个价值,这个价值是这个串的所有字母价值之和,如果 ...

  4. POWEROJ 2610 判断回文串 【HASH】

    题目链接[https://www.oj.swust.edu.cn/problem/show/2610] 题意:给你一个字符串,让你判断这个字符串是不是回文串,字符串的长度是1<len<1e ...

  5. hdu 3294 manacher 求回文串

    感谢: http://blog.csdn.net/ggggiqnypgjg/article/details/6645824/ O(n)求给定字符串的以每个位置为中心的回文串长度. 中心思想:每次计算位 ...

  6. HDOJ 5421 Victor and String 回文串自己主动机

    假设没有操作1,就是裸的回文串自己主动机...... 能够从头部插入字符的回文串自己主动机,维护两个last点就好了..... 当整个串都是回文串的时候把两个last统一一下 Victor and S ...

  7. UVA-11584 Partitioning by Palindromes 动态规划 回文串的最少个数

    题目链接:https://cn.vjudge.net/problem/UVA-11584 题意 给一个字符串序列,问回文串的最少个数. 例:aaadbccb 分为aaa, d, bccb三份 n< ...

  8. Python实现判断回文串

    回文数的概念:即是给定一个数,这个数顺读和逆读都是一样的.例如:121,1221,a,aa是回文数,123,1231不是回文数.  while 1: String = input('请先输入一个字符串 ...

  9. 401 Palindromes(回文词)

      Palindromes  A regular palindrome is a string of numbers or letters that is the same forward as ba ...

随机推荐

  1. 九度OJ 1453 Greedy Tino -- 动态规划

    题目地址:http://ac.jobdu.com/problem.php?pid=1453 题目描述: Tino wrote a long long story. BUT! in Chinese... ...

  2. 九度OJ 1081 递推数列 -- 矩阵二分乘法

    题目地址:http://ac.jobdu.com/problem.php?pid=1081 题目描述: 给定a0,a1,以及an=p*a(n-1) + q*a(n-2)中的p,q.这里n >= ...

  3. 无刷新分页 Ajax,JQuery,Json

    1.数据库设计 字段:Id(int) , Msg(varchar(MAX)) , PostDate(datetime) 2.自定义SQL查询方法(强类型DataSet) //SelectCount() ...

  4. 【原创】Linux下获取命令的帮助与常用命令

    Linux中的shell命令一般是执行步骤:用户在终端输入命令回车,系统内核会在当前用户的环境变量PATH中去读取环境变量的值 变量的值就是命令的路径,命令路径不只一个,于是系统会从这些路径中从左至右 ...

  5. jQuery弹出层_点击自身以外地方关闭弹出层

    <html> <style> .hide{display:none;} </style> <script type="text/javascript ...

  6. CI源码学习 一步一步重写 CodeIgniter 框架

    文章:http://www.cnblogs.com/zhenyu-whu/archive/2013/08.html

  7. mysql 存储引擎 myisam innodb 区别

    虽然MySQL里的存储引擎不只是MyISAM与InnoDB这两个,但常用的就是它俩了.可能有站长并未注意过MySQL的存储引擎,其实存储引擎也是数据库设计里的一大重要点,那么博客系统应该使用哪种存储引 ...

  8. 什么是php?以及mysqlnd与libmysqlclient

    今天想彻底搞清楚php与mysql的关系,于是在php官方网站(http://php.net/manual/en/mysqli.installation.php) 看了一下mysqli,mysql.感 ...

  9. yii之srbac详解

    一.安装篇 1.下载http://www.yiiframework.com/extension/srbac/ 将解压得到的srbac文件夹放在moudles目录下. 2.在项目的主配置文件中mai.p ...

  10. odoo 清除所有运行数据

    测试odoo,如果需要一个干净的db.经常需要清除掉所有业务数据.做如下操作,较为方便 1:建立一个服务器动作,动作的python代码入下. 然后新建一个菜单,菜单动作关联到 这个动作.需要清空db, ...