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. Linux常用指令【转载】

    [收藏]Linux常用指令[转载] $ 命令行提示符 粗体表示命令 斜体表示参数 filename, file1, file2 都是文件名.有时文件名有后缀,比如file.zip command 命令 ...

  2. Final 个人最终作业。

    1.对软件工程M1/M2做一个总结 在M1阶段,我在C705组.M1阶段我与黄漠源同学结对,一起完成提取关键词算法的优化.最初我们一起测试提取关键词算法功能的实现效果,随后我主要负责从网络上搜寻并整理 ...

  3. 北航MOOC客户端

    我们的团队作业终于完成了,欢迎下载使用我们的北航MOOC手机客户端软件(Android端)——北航学堂,学习北航的公开课程. 安装包下载地址: http://pan.baidu.com/s/1jGvH ...

  4. PAT 1082 射击比赛

    https://pintia.cn/problem-sets/994805260223102976/problems/994805260990660608 本题目给出的射击比赛的规则非常简单,谁打的弹 ...

  5. java mail session使用Properties的clone方法

    /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreem ...

  6. Oracle一次可以查询多个表的结果的方法

    select (select count(1) from gspauresult) 权限总表, (select count(1) from gspau01result) 权限总表1, (select ...

  7. [转帖]IBM POWER系列处理器的前世今生

    IBM POWER系列处理器的前世今生 Power是Power Optimization With Enhanced RISC的缩写,是由IBM开发的一种RISC指令集架构(ISA). IBM的很多服 ...

  8. GlusterFs卷的简单操作

    一.创建卷 gluster volume create 例子:gluster volume create gv0 replica 2 server1:/data/brick1/gv0 server2: ...

  9. Lodop多分出空白页的可能(情况1)

    在用Lodop进行打印超文本的时候,本身内容看上去只有一页,却分页分出空白的一页,很有可能有不可见内容的存在,下面是测试的一种情况,如html内部有内容占着空间,却是不可见的,如一些对象,或者如测试内 ...

  10. Python中正则表达式的巧妙使用

    字符串的匹配查询 re模块中的findall函数可以对指定的字符串进行遍历匹配,获取字符串中所有匹配的子串,并返回一个列表结果.该函数的参数含义如下: findall(pattern, string, ...