Palindromes

链接:http://acm.hdu.edu.cn/showproblem.php?pid=2163

(此题是为了对于JAVA温故知新的)

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
 


JAVA代码:

import java.util.Scanner;

/**
*
*/ /**
* @author lenovo
*
*/
public class Main { /**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int i = 1;
while(input.hasNextLine()) {
String string = input.nextLine();
if(string.equals("STOP")) {
break;
}
else{StringBuffer stringBuffer = new StringBuffer(string);
String string2 = stringBuffer.reverse().toString();
if(string2.equals(string)) {    # 注意JAVA比较时是用equal()方法的。
System.out.println("#" + i + ": YES");
}
else {
System.out.println("#" + i + ": NO");
}
i++;
}
}
} }

C++代码:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int T=;
string a;
while(cin>>a)
{
if(a=="STOP")
break;
T++;
string b;
b=a;
reverse(b.begin(),b.end());
if(b==a)
printf("#%d: YES\n",T);
else
printf("#%d: NO\n",T);
}
return ;
}

(reverse)Palindromes hdu2163的更多相关文章

  1. Palindromes _easy version(reverse)

    Problem Description “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串.请写一个程序判断读入的字符串是否是“回文”.   Input 输入包 ...

  2. hdu 1318 Palindromes

    Palindromes Time Limit:3000MS     Memory Limit:0KB     64bit                                         ...

  3. 65. Reverse Integer && Palindrome Number

    Reverse Integer Reverse digits of an integer. Example1: x =  123, return  321 Example2: x = -123, re ...

  4. 【LeetCode】9 & 234 & 206 - Palindrome Number & Palindrome Linked List & Reverse Linked List

    9 - Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Som ...

  5. hdu 1318 Palindromes(回文词)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1318 题意分析:输入每行包含一个字符串,判断此串是否为回文串或镜像串. 表面上看这道题有些复杂,如果能 ...

  6. 401 Palindromes(回文词)

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

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

    Problem Description Write a program to determine whether a word is a palindrome. A palindrome is a s ...

  8. Palindromes _easy version

    Palindromes _easy version Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  9. Palindromes

    http://acm.hdu.edu.cn/showproblem.php?pid=1318 Palindromes Time Limit: 2000/1000 MS (Java/Others)    ...

随机推荐

  1. 对于windows 10使用感受

    windows 10是美国微软公司研发的新一代跨平台及设备应用的操作系统.在2015年7月29日12点起,windows 10推送全面开始,windows 7.windows 8 用户可以升级到win ...

  2. Note: SE Class's Individual Project

    虽然第一个Project还有点小问题需要修改,但是大体已经差不多了,先把blog记在这里,算是开博第一篇吧! 1.项目预计的用时 本来看到这个题的时候想的并不多,但是看了老师的要求才觉得如此麻烦ORZ ...

  3. 冲刺Two之站立会议9

    今天我们团队主要针对软件的功能进行了改进.因为它目前可以实现视频通话,语音聊天,文件传输和文字聊天的通信功能,我们想要在它的基础上实现临时局域群聊和群聊视频的功能,目前还没有完全实现.

  4. <构建之法>第11、12章

    第11章软件设计与实现 主要讲了典型的开发流程和开发阶段的一些管理方法 问题: 从spec道实现是代码的实现吗? 第12章 用户体验 主要讲了用户体验的各种角度和认识阻力登 问题: 用户的体验是设计前 ...

  5. 3-palindrome CodeForces - 805B (思维)

    In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so ...

  6. solr6.2单机版安装

    1安装solr服务,先安装jdk和tomcat 2去官网(http://archive.apache.org/dist/lucene/solr/)下载solr压缩包,最新版本是6.4.1,下载解压后, ...

  7. Selenium的自我总结1

    搞了一段时间的Selenium Web的自动化,针对项目要搭建了一套适合项目的测试框架(Selenium[POM/DataDriver]+TestNG+Ant+Jenkins).在最开始看Seleni ...

  8. jquery 動畫

    animate({param},speed,callback)/animate({param},speed)/animate({param}) param表示css屬性:屬性名必須是camel標識法: ...

  9. 2.18比赛(T2,T3留坑)

    2.18比赛(T2,T3留坑) pdf版题面 pdf版题解 超越一切(ak) [题目描述] 夏洛可得到一个(h+1)×(w+1)的巧克力,这意味着她横着最多可 以切 h 刀,竖着最多可以切 w 刀 她 ...

  10. python----面对对象三大特征2

    多态 什么是多态?多态指的是一类事物有多种形态,例如一个动物类,狗和猫都通过继承动物类来得来,这样我们可以将狗.猫称作动物类的另一种形态. 在java中也存在多态,java中的多态是用来解决在一个函数 ...