HDOJ/HDU 2163 Palindromes(判断回文串~)

简介: HDOJ/HDU 2163 Palindromes(判断回文串~)

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");
            }
        }
    }
}


目录
相关文章
|
6月前
|
Java
hdu-2112-HDU Today(dijkstra + map)
hdu-2112-HDU Today(dijkstra + map)
23 0
hdu 1196 Lowest Bit(水题)
hdu 1196 Lowest Bit(水题)
41 0
hdoj 3555 BOMB(数位dp)
hdoj 3555 BOMB(数位dp)
37 0
codeforces 339A.Helpful Maths B.Xenia and Ringroad 两水题
.题意就是把字符串里面的数字按增序排列,直接上代码。
40 0
poj 2362 hdoj 1518 Square(搜索)
不难了解,小棒子的长度越长,其灵活性越差。例如长度为5的一根棒子的组合方式要比5根长度为1的棒子的组合方式少,这就是灵活性的体现。
49 0
hdoj 3466 Proud Merchants(01背包)
想想我们为什么要排序, 举个简单的例子,如果数据中出现这样到情况 5 9 3、 6 6 5、5 6 3…… 对5 9 3 处理的时候他只能求出dp[9]然后6 6 5只能在dp[9]的基础上继续处理,它要用到dp[6]、dp[7]……,而这些全是零,但这些一直会是0吗?不是在处理5 6 3的时候可以得到这些值,但6 6 5已经被处理了,它再也不会用的这些了,所以怎么得到正确的结果? 如果我们对5 6 3优先处理就不会出现这样到情况了。
34 0
HDOJ 1056 HangOver(水题)
HDOJ 1056 HangOver(水题)
100 0
HDOJ 1056 HangOver(水题)
HDOJ/HDU 2700 Parity(奇偶判断~)
HDOJ/HDU 2700 Parity(奇偶判断~)
142 0
|
机器学习/深度学习 人工智能 BI
HDOJ/HDU 2550 百步穿杨(注意排序)
HDOJ/HDU 2550 百步穿杨(注意排序)
106 0