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

Re:each of the elements of the string is changed to its reverse (if it has a reverse)

Posted by BU at 2006-03-18 14:26:32 on Problem 1590
In Reply To:each of the elements of the string is changed to its reverse (if it has a reverse) Posted by:sza at 2006-03-05 00:51:48
> each of the elements of the string is changed to its reverse (if it has a reverse),有歧异。正确理解是如果串中没有reverse则不为mirrored string。但题中的意思给人的感觉是如果存在reverse的情况下则替换,不存在是就不管,而非不存在就直接判断不为mirrored string,害得我WA了好多次。
#include<stdio.h>
#include<string.h>
char s[100]="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
char m[100]="A   3  HIL JM O   2TUVWXY51SE Z  8 ";
int get_dex(char ch)
{
	int i;
	for(i=0;i<=34;i++)
		if(ch==s[i])
			return i;
}
int main()
{
	int l,i,j,flag_m,flag_p;
	char a[100],str[100];
	char p[100],mirror[100],Mirror[100];
	while(scanf("%s",a)!=EOF)
	{
		l=strlen(a);
		strcpy(str,a);
		for(i=0;i<=l-1;i++)
			if(a[i]=='0')
				a[i]='O';
		for(i=0;i<=l-1;i++)
			p[l-1-i]=a[i];
		flag_p=0;
		p[l]='\0';
	//	printf("dd  %s\n",p);
		if(strcmp(a,p)==0)
			flag_p=1;
		flag_m=1;
		for(i=0;i<=l-1;i++)
            if(m[get_dex(a[i])]==' ')
			{
				flag_m=0;
				break;
			}
		if(flag_m==1)
		{
			for(i=0;i<l;i++)
			{
				int dex=get_dex(a[i]);
				mirror[i]=m[dex];
			}
			mirror[l]='\0';
			for(i=0;i<=l-1;i++)
				Mirror[i]=mirror[l-1-i];
			Mirror[l]='\0';
			if(strcmp(Mirror,a)!=0)
				flag_m=0;
		}
		if(flag_p==1&&flag_m==1)
			printf("%s -- is a mirrored palindrome.\n",str);
		else
			if(flag_p==1&&flag_m==0)
			printf("%s -- is a regular palindrome.\n",str);
		else
			if(flag_p==0&&flag_m==1)
			printf("%s -- is a mirrored string.\n",str);
		else
			printf("%s -- is not a palindrome.\n",str);
//		printf("mirror %s\n",mirror);
//		printf("pal    %s\n",p);
		printf("\n");
	}
	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