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

每行后有空格,没有镜像字母就不是镜像string(附AC代码)

Posted by ls2412126 at 2015-06-01 00:41:40 on Problem 1590
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
bool isp(string king)
{
  int j=king.length()-1;
  int i=0;
   while(j>=i)
    {
	 if (king[j]!=king[i])
	 return false;
	 else 
	 {
	 i++;
	 j--;
	 }
	
	}
return true;
}
bool ism(string king)
{
 int j=king.length()-1;
 int i=0;
 string queen=king;
  for (int i=0;i<queen.length();i++)
  {
  	char what=queen[i];
   switch (what)
   {
    case 'E':queen[i]='3';
    break;
    case 'J':queen[i]='L';
    break;
    case 'L':queen[i]='J';
    break;
    case 'S':queen[i]='2';
    break;
    case 'Z':queen[i]='5';
    break;
    case '2':queen[i]='S';
    break;
    case '3':queen[i]='E';
    break;
    case '5':queen[i]='Z';
    break;
    case 'B':
	case 'C':
	case 'D':
	case 'F':
	case 'G':
	case 'K':
	case 'N':
	case 'P':
	case 'Q':
	case 'R':
	case '4':
	case '6':
	case '7':
	case '9':return false;
};
  };
  i=0;
  for (int j=king.length()-1;j>=0;j--)
  {
   if (queen[j]!=king[i])
   return false;
   else 
    {
	i++;
	}
  
  }
  return true;
  

}
int main()
{
 string king2;
  while(cin>>king2)
   {
    bool yzz=isp(king2);
    bool zzy=ism(king2);
     if (yzz && zzy)
      cout<<king2<<" -- is a mirrored palindrome."<<endl;
      if (!yzz && zzy)
       cout<<king2<<" -- is a mirrored string."<<endl;
       if(yzz && !zzy)
       cout<<king2<<" -- is a regular palindrome."<<endl;
       if (!yzz & !zzy)
        cout<<king2<<" -- is not a palindrome."<<endl;
    cout<<endl; 
   
   }

} 

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