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

坑题

Posted by KatrineYang at 2016-12-03 11:00:25 on Problem 1590
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

bool isP(char *str, int len){
	for(int i = 0; i < len/2; i++){
		if(str[i] != str[len-1-i]) return false;
	}
	return true;
}

char mr(char c){
	switch(c){
	    case 'A': case 'H': case 'I': case 'M': case 'O':
	    case 'T': case 'U': case 'V': case 'W': case 'X':
	    case 'Y': case '1': case '8':
	    	return c;
	    case 'E': return '3';
	    case '3': return 'E';
	    case 'J': return 'L';
	    case 'L': return 'J';
	    case 'S': return '2';
	    case '2': return 'S';
	    case 'Z': return '5';
	    case '5': return 'Z';
	    default: return '\0';
	}
}

bool isM(char *str, int len){
	for(int i = 0; i < (len+1)/2; i++){
		if(mr(str[i]) != str[len-1-i]) return false;
	}
	return true;
}

char desc[4][233] = {"not a palindrome", "a regular palindrome", "a mirrored string", "a mirrored palindrome"};

int main() {
	char str[233];
	while(scanf("%s", str) == 1){
		int len = strlen(str);
		int isp = isP(str, len), ism = isM(str, len);
		int idx = isp + 2 * ism;
		printf("%s -- is %s.\n\n", str, desc[idx]);
	}
	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