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. 北航学堂Android客户端Beta阶段测试报告

    我们已经知道的bug如下: 1.在没有网络的情况下,我们的程序会直接崩溃,没有弹出提醒网络异常的错误,这是个比较严重的bug,我们在6号7号 考试结束之后会进行修改: 有待进行的优化: 1.UI界面的 ...

  2. 剑指offer:树的子结构

    题目描述: 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) 解题思路: 同样考虑用递归来做. 利用两个递归函数,一个用于判断两棵树树否相等,另一个递归取A的 ...

  3. mysql 记录根据日期字段倒序输出

    我们知道倒序输出是很简单的 select * from table order by id desc 直接这样就可以 那么现在的问题在于日期字段怎么来倒序输出 这里我们用到cast()来将指定的字段转 ...

  4. SyntaxHighlighter行号显示错误问题解决方案

    SyntaxHighlighter是根据代码中的换行符分配行号的.但是,如果一行代码或者注释比较长,在页面显示时需要分成多行显示,会出现行号对不上的问题,像这样: 通过设置CSS强制不换行,可以保证行 ...

  5. [转帖]知乎专栏:正确使用 Docker 搭建 GitLab 只要半分钟

    正确使用 Docker 搭建 GitLab 只要半分钟 https://zhuanlan.zhihu.com/p/49499229 很多程序员在内网搭建 gitlab 都搭建的坑坑洼洼,不支持 htt ...

  6. Win2016以及win10 IIS10 下安装IEwebcontrol的方法

    1. 公司产品需要安装IE webcontrol控件 但是在win2016以及win10 上面安装时 因为IIS 已经升级到了IIS10 安装时会提示: 兼容解决的方法比较简单,修改注册表即可 HKE ...

  7. Eclipse 下载安装

    https://blog.csdn.net/qq_27200591/article/details/72823816(安装eclipse  copy) 第一步:下载eclipse,并安装. 下载链接: ...

  8. Python——socketsever模块

    1.作用:同时与多个客户端通信 import socketserver class MyServer(skcketserver.BaseRequestHandler): def handle(self ...

  9. BZOJ1775[USACO 2009 Dec Gold 3.Video Game Troubles]——DP

    题目描述 输入 * 第1行: 两个由空格隔开的整数: N和V * 第2到第N+1行: 第i+1行表示第i种游戏平台的价格和可以在这种游戏平台上面运行的游 戏.包含: P_i, G_i还有G_i对由空格 ...

  10. BZOJ4200 NOI2015小园丁与老司机(动态规划+上下界网络流)

    一看上去就是一个二合一的题.那么先解决第一部分求最优路线(及所有可能在最优路线上的线段). 由于不能往下走,可以以y坐标作为阶段.对于y坐标不同的点,我们将可以直接到达的两点连边,显然这样的边的个数是 ...