(reverse)Palindromes hdu2163
Palindromes
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2163
(此题是为了对于JAVA温故知新的)
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”.
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.
string. The line should include “#”, followed by the problem number, followed by
a colon and a space, followed by the string “YES” or “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的更多相关文章
- Palindromes _easy version(reverse)
Problem Description “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串.请写一个程序判断读入的字符串是否是“回文”. Input 输入包 ...
- hdu 1318 Palindromes
Palindromes Time Limit:3000MS Memory Limit:0KB 64bit ...
- 65. Reverse Integer && Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, re ...
- 【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 ...
- hdu 1318 Palindromes(回文词)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1318 题意分析:输入每行包含一个字符串,判断此串是否为回文串或镜像串. 表面上看这道题有些复杂,如果能 ...
- 401 Palindromes(回文词)
Palindromes A regular palindrome is a string of numbers or letters that is the same forward as ba ...
- HDOJ/HDU 2163 Palindromes(判断回文串~)
Problem Description Write a program to determine whether a word is a palindrome. A palindrome is a s ...
- Palindromes _easy version
Palindromes _easy version Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- Palindromes
http://acm.hdu.edu.cn/showproblem.php?pid=1318 Palindromes Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- CF367C. Hard problem
链接[http://codeforces.com/group/1EzrFFyOc0/contest/706/problem/C] 题意: 他希望它们按词典顺序排序(就像字典中那样),但他不允许交换其中 ...
- 701 C. They Are Everywhere
链接 [http://codeforces.com/group/1EzrFFyOc0/contest/701/problem/C] 题意 给你一个包含大小写字母长度为n的字符串,让你找包含所有种类字符 ...
- 网络:OSPF理解
OSPF(开放最短路径优先)协议使用Dijkstra算法,常见的版本有:OSPFv2.OSPFv3等.以下主要介绍OSPFv2,OSPFv3是面向IPv6的且不兼容IPv4. 1.工作过程: 1)每台 ...
- Leetcode——258.各位相加【水题】
给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数. 示例: 输入: 38 输出: 2 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2. 由于 2 是一位数,所 ...
- Sprint 冲刺第三阶段第二天
陈汝婷:播放音乐 1:做播放音乐这个功能时开始没有考虑周全,使用 PS P出来的图竟然没有用上,耗时耗人工.吃一见长一智,以后要考虑周全.还要耗了那么久,音乐的初效果终于出来了. 2:昨天出现的问题, ...
- Linux (centos7) 防火墙命令
防火墙配置 CentOS 7默认使用的是firewall作为防火墙,这里改为iptables防火墙. firewall操作: # service firewalld status; #查看防火墙状态 ...
- auto_increment 自增键的一些说明
导致auto_increment变小的几种情况: 1. alter table xx auto_increment = yy; 2. truncate table 3. restart mysql 第 ...
- Async和Await 异步方法
Async和Await关键字是C#异步编程的核心.通过使用这两个关键字,你可以使用.NET Framework或Windows Runtime的资源创建一个异步方法如同你创建一个同步的方法一样容易.通 ...
- Spark_RDD之RDD基础
1.什么是RDD RDD(resilient distributed dataset)弹性分布式数据集,每一个RDD都被分为多个分区,分布在集群的不同节点上. 2.RDD的操作 Spark对于数据的操 ...
- Java常用工具方法
以GET请求形式获取文本文件内容 /** * 以GET请求形式获取文本文件内容 * @param url http下载地址,比如http://www.abc.com/123.css * @return ...