HDU 2163 Palindromes

Palindromes

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2949    Accepted Submission(s): 1723

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

我想shi的心都有了,那天考试连A三次都没过,思路也没啥问题啊!事后突然发现大写的O不知怎么的被写写成小写的了。哎,不然名次就上升好几名了

#include<stdio.h>
#include<string.h>
char a[60];
int main()
{
	int t,len,i,j,m=1,b,c,d;
	while(scanf("%s",a)!=EOF)
	{
		if(!strcmp(a, "STOP")) break;
		printf("#%d: ",m++);
		b=c=d=0;
		len=strlen(a);
		if(len==1)    {printf("YES\n");continue;}
		t=len/2;
		if(len%2==0)
		{
			for(i=0;i<t;i++)
			{
				if(a[i]==a[len-1-i])
				b++;
			}
			if(b==t)  printf("YES");
			else    printf("NO");
		}

		else
		{
			for(i=0;i<=t;i++)
			{
				if(a[i]==a[len-1-i])
				c++;
			}
			if(c-1==t)   printf("YES");
			else   printf("NO");
		}
		printf("\n");
	}
	return 0;
}

HDU 2163 Palindromes

时间: 2025-01-17 16:16:20

HDU 2163 Palindromes的相关文章

HDOJ/HDU 2163 Palindromes(判断回文串~)

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 palindro

hdu 2029 Palindromes _easy version

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2029 题目大意:回文数,即第一个和最后一个相同,第二个和倒数第二个相同....以此类推 注意字符的输入,以及计算字符长度的位置.还有要注意清流哦~ 1 #include <stdio.h> 2 #include <string.h> 3 int main (void) 4 { 5 int m,n,i,l; 6 char a[100]; 7 while (scanf("%d&q

hdu 1318 Palindromes(回文词)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1318 题意分析:输入每行包含一个字符串,判断此串是否为回文串或镜像串. 表面上看这道题有些复杂,如果能熟练运用字符数组的话,代码也颇为简洁.. /*Palindromes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 657 Accepted

HDU 1544 Palindromes(回文子串)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1544 问题分析: 问题要求求出字符串的连续子串中的回文子串个数.首先,需要区分连续子串与子序列的区别. 连续子串为连续的字符组成的字符串:子序列需要满足在子序列中出现的字符的相对顺序与字符串中出现的相对顺序相同. 问题的解法:根据回文子串的长度分为奇数与偶数分为两种可能: 1.当回文子串长度为奇数时,中间的字符为任意字符,取除了字符串最左边与最右边的字符的其他字符,通过向两边拓展来判断 奇数回文子串

HDU 2163

Palindromes Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3185    Accepted Submission(s): 1867 Problem Description Write a program to determine whether a word is a palindrome. A palindrome is

HDU 5340-Three Palindromes(Manacher算法)

题目地址:HDU 5340 题意:问是否能将字符串str分解为三段非空的回文串. 思路:我们根据Manacher算法对字符串进行处理,处理过程中产生的P数组,我们可以得到两个数组first和last. first存储的是第一个回文串的半径可能值. last存储的是第三个回文串的半径可能值. 根据first和last我们可以枚举第一个回文串和第三个回文串,然后根据半径找出第二个回文串的初始位置和结束位置.然后计算出第二个回文串的中点: 1.如果ll>rr,则第二个字符串的长度为负数,pass 2.

HDU 1544 Palindromes(回文字符子串)

A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is read from ri

hdu 5340 Three Palindromes(字符串处理+ 回文)

hdu 5340 Three Palindromes 问题描述 判断是否能将字符串S分成三段非空回文串. 输入描述 第一行一个整数T,表示数据组数.T \leq 20T≤20 对于每一个组,仅包含一个由小写字母组成的串.1 \leq |S| \leq 200001≤∣S∣≤20000 输出描述 对于每一组,单行输出"Yes" 或 "No". 输入样例 2 abc abaadada 输出样例 Yes No 题目大意:给出一个字符串,判断,是否能将其分成三个不为空的回文

hdu 3948 The Number of Palindromes

The Number of Palindromes Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)http://acm.hdu.edu.cn/showproblem.php?pid=3948 Problem Description Now, you are given a string S. We want to know how many distinct substri