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. bootstrap是什么

    Bootstrap,来自 Twitter,是目前最受欢迎的前端框架. Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷. 本教程将向您讲解 ...

  2. 【MOOC EXP】Linux内核分析实验六报告

    程涵  原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 进程的描述和进程的创建 知识点梳理: ...

  3. Linux内核第六节 20135332武西垚

    如何描述一个进程:进程描述符的数据结构: 如何创建一个进程:内核是如何执行的,以及新创建的进程从哪里开始执行: 使用gdb跟踪新进程的创建过程. 进程的描述 操作系统三大功能: 进程管理(最核心最基础 ...

  4. 20150409作业3 阅读《构建之法》1-5章 (Update:2015-04-16

    以下是我看<构建之法>1-5章列出来的知识点和一些自己对部分知识的理解以及一些吐槽...和感受 1.1 软件 = 程序 + 软件工程 (软件工程 = 软件 - 程序(我知道软件是什么,也知 ...

  5. PAT 甲级 1044 Shopping in Mars

    https://pintia.cn/problem-sets/994805342720868352/problems/994805439202443264 Shopping in Mars is qu ...

  6. What is the difference between apache tomcat deployer and core version? - Stack Overflow

    java - What is the difference between apache tomcat deployer and core version? - Stack Overflowhttps ...

  7. SpringBoot(十七)_springboot跨域处理

    本文转自:Vi的技术博客 什么是跨域 首先,我们需要了解一下一个URL是怎么组成的: // 协议 + 域名(子域名 + 主域名) + 端口号 + 资源地址 http: + // + www.baidu ...

  8. 激活win10专业版

    每180天激活一次

  9. html5 画布和SVG的差别

    canvas和SVG可以在浏览器绘制图形,但是本质上是不同的.canves是绘制2d图象,SVG也是绘制2d图象. Canvas是Javascript进行绘图的,是逐像素绘图.Canvas一旦图象绘制 ...

  10. 03 基于umi搭建React快速开发框架(封装列表增删改查)

    前言 大家在做业务系统的时候,很多地方都是列表增删改查,做这些功能占据了大家很长时间,如果我们有类似的业务,半个小时就能做出一套那是不是很爽呢. 这样我们就可以有更多的时间学习一些新的东西.我们这套框 ...