回文字符串
2013-05-16 23:35
204 查看
题目1192:回文字符串
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:2178
解决:962
题目描述:
给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的。
输入:
输入包括一行字符串,其长度不超过1000。
输出:
可能有多组测试数据,对于每组数据,如果是回文字符串则输出"Yes!”,否则输出"No!"。
样例输入:
样例输出:
来源:2007年华中科技大学计算机研究生机试真题
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:2178
解决:962
题目描述:
给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的。
输入:
输入包括一行字符串,其长度不超过1000。
输出:
可能有多组测试数据,对于每组数据,如果是回文字符串则输出"Yes!”,否则输出"No!"。
样例输入:
hellolleh helloworld
样例输出:
Yes! No!
来源:2007年华中科技大学计算机研究生机试真题
#include <stdio.h> #include <string> #include <algorithm> #include <string.h> using namespace std; char str1[1010]; int main() { string s, t; while(scanf("%s", str1) != EOF) { s = str1; t = str1; reverse(t.begin(), t.end()); if(s == t) printf("Yes!\n"); else printf("No!\n"); } return 0; }