游客 Signup | Login
中文 | En

2182 - P510 4

P510 4

Input

一行字符串,可以有空格

Output

字符串反向后的结果(去除空格,所有字母用小写表示)

yes表示是回文,no表示不是回文

Examples

Input

madam I'm adam

Output

madamimadam
yes

Solution C++

#include<iostream>
#include<cstring>
using namespace std;
char ch(char st,int &i)
{
	if(st>='A'&&st<='Z')
		return st+('a'-'A');
	else
		return st;
}
int main()
{
	char st[100010],after[100010],o=0;
	gets(st);
	int len=strlen(st);
	for(int i=0;i<len;i++)
		after[i]=ch(st[i],i);
	for(int i=len-1;i>=0;i--)
	{
		if(after[i]>='a'&&after[i]<='z')
			cout << after[i];
	}
	cout << endl;
	bool z=1;
	int j=0,k=len-1;
	for( ;j<k;j++,k--)
	{
		if(after[j]<'a'||after[j]>'z')
		{
			k++;
			continue;
		}
		if(after[k]<'a'||after[k]>'z')
		{
			j--;
			continue;
		}
		if(after[j]!=after[k])
		{
			z=0;
			break;
		}
	}
	if(z==0)
		cout << "no" << endl;
	else
		cout << "yes" << endl;
	return 0;
}

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题