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. FBX SDK 从2012.1 到 2013.3 变化

    ==================================================== ============================== 译文               ...

  2. php计算最后一次,第一次字符串出现位置

    strpos($str, n) 首次,n在str第一次出现位置, strrpos($str, n) 最后一次,n在str最后一次出现位置 strripos区分大小写

  3. jQuery登陆判断简单实现代码

    登陆判断在实际应用中还是比较常见,在客户端执行判断可以减少服务器端的负担,感兴趣的朋友可以参考下 复制代码代码如下: <script src="jquery-1.9.1.js" ...

  4. 2015年9月29日 sql 触发器

    触发器(trigger):当有关联操作的时候使用(级联操作),属于ddl关键字. eg:下订单时,创建中的商品数量要减少:退票时,总的票数要增加.         在订单上建立触发器         ...

  5. armv7a-mediatek451_001_vfp-linux-gnueabi-gcc: directory: No such file or directory 编译error

    release/vm_linux/output/hisense_android/mt5399_cn_android_JB/rel/obj/oss/source/arm_mali_ko/mali400- ...

  6. Spring和Hibernate相遇

    Spring是一个很贪婪的家伙,看到他的长长的jar包列表就知道了,其实对于hibernate的所有配置都是可以放在Spring中来进行得,但是我还是坚持各自分明,Spring只是负责自动探测声明类( ...

  7. 【转载】C# Tutorial - Simple Threaded TCP Server

    http://tech.pro/tutorial/704/csharp-tutorial-simple-threaded-tcp-server In this tutorial I'm going t ...

  8. python中self.__class__

    1. python中的self python中的self就相当于C++中的this指针也就是指向对象本身的指针self.name = name 就是当前对象的成员变量name赋值为name. 2.py ...

  9. bzoj 1964: hull 三维凸包 计算几何

    1964: hull 三维凸包 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 54  Solved: 39[Submit][Status][Discuss ...

  10. underscore

    http://www.byywee.com/page/M0/S819/819654.html http://www.haogongju.net/art/1127253 http://hi.baidu. ...