Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

跪求牛人 例子都OK了 不知道哪组数据没过~ (有代码)

Posted by mzzdl at 2010-04-16 20:17:24 on Problem 1590
#include<iostream>
using namespace std;

char ch[100];
char ch_temp[100];
int length;
int huiwen;
int huizi;
int main()
{
	while(cin>>ch)
	{
		int i,j;
		huiwen=huizi=0;
		for(i=0;ch[i]!='\0';i++)
		{	
			if(ch[i]<'A'||ch[i]>'Z')
			{
				
				if(ch[i]<'1'||ch[i]>'9')
					return 0;
				
			}
		}	
		length=i;
		for(j=0;j<=length;j++)
		{
			i--;
			ch_temp[j]=ch[i];			
		}
		ch_temp[length]='\0';
		//hui wen
		j=0;
		for(i=0;i<=length;i++)
		{
			if(ch[i]==ch_temp[i])
			{
				j++;
			}
			if(j==length+1)
			{
				huiwen=1;
			}

		}
		//hui zi

		if(1)
		{
			i=length;
			for(j=0;j<=length;j++)
			{
				i--;
				ch_temp[j]=ch[i];			
			}
			for(j=0;j<length;j++)
			{
				if(ch_temp[j]=='3')
					ch_temp[j]='E';
				else if(ch_temp[j]=='E')
					ch_temp[j]='3';
				if(ch_temp[j]=='J')
					ch_temp[j]='L';
				else if(ch_temp[j]=='L')
					ch_temp[j]='J';
				if(ch_temp[j]=='S')
					ch_temp[j]='2';
				else if(ch_temp[j]=='2')
					ch_temp[j]='S';
				if(ch_temp[j]=='Z')
					ch_temp[j]='5';
				else if(ch_temp[j]=='5')
					ch_temp[j]='Z';					
			}
		}
		j=0;
		for(i=0;i<length;i++)
		{
			if(ch[i]==ch_temp[i])
			{
				j++;
			}
		}	
		if(j==length)
		{
			huizi=1;
		}
		//cout<<huizi<<endl;

		
		
		if(huiwen==1)
		{
			if(huizi==1)
				cout<<ch<<" -- is a mirrored palindrome."<<endl;
			else
				cout<<ch<<" -- is a regular palindrome."<<endl;
		}
		else if(huizi==1)
		{
			cout<<ch<<" -- is a mirrored string."<<endl;
		}
		else
			cout<<ch<<" -- is not a palindrome."<<endl;
		
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator