Page 3 of 14

Posted: Fri Nov 29, 2002 11:24 pm
by alun
try this...

Code: Select all

int main() {
  char inp[21],lu[100]={0},lm[100]={0};
  int i,j,k,m,y,t; 
  lu['A']='A'; lu['E']='3'; lu['H']='H'; lu['I']='I';
  lu['J']='L'; lu['L']='J'; lu['M']='M'; lu['O']='O';
  lu['S']='2'; lu['T']='T'; lu['U']='U'; lu['V']='V';
  lu['W']='W'; lu['X']='X'; lu['Y']='Y'; lu['Z']='5';
  lu['2']='S'; lu['3']='E'; lu['5']='Z'; lu['8']='8';

  lm['A']='A'; lm['H']='H'; lm['I']='I';
  lm['M']='M'; lm['O']='O';
  lm['T']='T'; lm['U']='U'; lm['V']='V';
  lm['W']='W'; lm['X']='X'; lm['Y']='Y';
  lm['8']='8';

  while (gets(inp)!=NULL) {
    i=strlen(inp);
    m=i-1;
    i/=2; 
    t=y=k=1;
    for (j=0;j<=i;j++,m--) {
      if (inp[m]!=inp[j]) t=0;
      if (inp[m]!=lu[inp[j]]) y=0;
      if (inp[m]!=lm[inp[j]]) k=0;
    }
    if (k) 
      printf("%s -- is a mirrored palindrome.\n\n",inp);
    else if (y)
      printf("%s -- is a mirrored string.\n\n",inp);
    else if (t) 
      printf("%s -- is a regular palindrome.\n\n",inp);
    else 
      printf("%s -- is not a palindrome.\n\n",inp);
  }
}

401

Posted: Thu Dec 26, 2002 12:14 pm
by route
[pascal]
Program pa;
type re=record
ch:array['A'..'Z'] of char;
nu:array['1'..'9'] of char;
end;
const cha:re=(ch:('A', ' ', ' ', ' ', '3', ' ',' ', 'H', 'I', 'L', ' ', 'J',
'M', ' ', 'O', ' ', ' ', ' ', '2', 'T', 'U', 'V', 'W', 'X',
'Y', '5');
NU:('1', 'S', 'E', ' ', 'Z', ' ', ' ', '8', ' '));
var i:longint;
s:string;
mirror, palin:boolean;

begin
while not eof do
begin
readln(s);
palin:=true;
for i:=1 to length(s) div 2 do
If s <> s[length(s)+1-i] then
begin palin:=false; break end;
mirror:=true;
for i:=1 to length(s) div 2 do
begin
If s in ['A'..'Z'] then
If (cha.ch[s] <> s[length(s)+1-i]) then mirror:=false;
If s in ['1'..'9'] then
If (cha.nu[s] <> s[length(s)+1-i]) then mirror:=false;
If mirror=false then break;
end;
i:=length(s) div 2 + 1;
If not mirror and odd(length(s)) then
If (s in ['A'..'Z']) and (s <> cha.ch[s]) then mirror:=false
else if (s in ['1'..'9']) and (s <> cha.nu[s[i]]) then mirror:=false;
If not mirror and not palin then writeln(s, ' -- is not a palindrome.')
else if mirror then
If palin then writeln(s, ' -- is a mirrored palindrome.')
else writeln(s, ' -- is a mirrored string.')
else writeln(s, ' -- is a regular palindrome.');
writeln
end;
end.
[/pascal]

WA... thanks for helping

input for 401

Posted: Tue Dec 31, 2002 7:40 am
by deddy one
what is the output for

B3EB

is it not a palindrome??

and can anyone give me anothe test case for this
tricky mirror thing

thx.

Posted: Tue Dec 31, 2002 11:05 am
by angga888
B3EB is not a palindrome.

Try this input also :
MAIAM is a mirrored palindrome
123ESI is not a palindrome
123ES1 is a mirrored string
DEO3D is not a palindrome
9339 is a regular palindrome

Good Luck!

Happy New Year 2003 for everybody.
Angga888 :lol:

Posted: Tue Dec 31, 2002 8:06 pm
by deddy one
thx
but apparently my problem is when the input is a blank line
if it's a blank line it should be not a palindrome
(my code before determine it as palindrome)

I got AC now , thx angga

Posted: Fri Jan 03, 2003 2:47 pm
by zsepi
deddy one wrote:apparently my problem is when the input is a blank line
There is no input when the string would be an empty string....
Input consists of strings (one per line) each of which will consist of one to twenty valid characters
However, I would say that the specification of the output is rather contradictory, so it's useful to read both the spec and the sample output...

Posted: Fri Jan 03, 2003 3:07 pm
by deddy one
well, actually I've made some minor changes before I resubmit the
problem again, I don't exactly remember what changes that I made
but definitely my changes made me got AC

after I read the problem again, well, if there is an empty string
then the output is a palindrome after all.

:D

401 WA! Help me anyboby, please!

Posted: Fri May 02, 2003 4:47 pm
by medv
Why do I have WA? What's wrong in my program? Help me, please!

My code is below.

program p401;
var
palin,mirr:boolean;
Rev:array[0..255] of integer;
i:integer;
s:string;

function palindrome(s:string):boolean;
var
i,j:integer;
begin
i := 1; j := length(s);
while (i <= j) do
begin
if s[i] <> s[j] then
begin
palindrome := False;
Exit;
end;
Inc(i); Dec(j);
end;
palindrome := True;
end;

function mirror(s:string):boolean;
var
i,j:integer;
begin
i := 1; j := length(s);
while (i <= j) do
begin
if ((Rev[Ord(s[i])] = 0) or (Rev[Ord(s[i])] <> Ord(s[j]))) then
begin
mirror := False;
Exit;
end;
Inc(i); Dec(j);
end;
mirror := True;
end;

begin
for i:=0 to 255 do Rev[i] := 0;

Rev[Ord('A')] := Ord('A');
Rev[Ord('E')] := Ord('3');
Rev[Ord('H')] := Ord('H');
Rev[Ord('I')] := Ord('I');
Rev[Ord('J')] := Ord('L');
Rev[Ord('L')] := Ord('J');
Rev[Ord('M')] := Ord('M');
Rev[Ord('O')] := Ord('O');
Rev[Ord('T')] := Ord('T');
Rev[Ord('U')] := Ord('U');
Rev[Ord('V')] := Ord('V');
Rev[Ord('W')] := Ord('W');
Rev[Ord('X')] := Ord('X');
Rev[Ord('Y')] := Ord('Y');
Rev[Ord('Z')] := Ord('5');
Rev[Ord('1')] := Ord('1');
Rev[Ord('2')] := Ord('S');
Rev[Ord('3')] := Ord('E');
Rev[Ord('5')] := Ord('Z');
Rev[Ord('8')] := Ord('8');

while True do
begin
readln(s);
palin := palindrome(s);
mirr := mirror(s);
write(s,' -- is ');
if palin then
if (not mirr) then writeln('a regular palindrome.')
else writeln('a mirrored palindrome.')
else if (not mirr) then writeln('not a palindrome.')
else writeln('a mirrored string.');
if eof(input) then break;
writeln;
end;
end.

Posted: Thu Jun 12, 2003 9:42 pm
by keya
Why does this code produce WA??? :(

[cpp]#include<stdio.h>
#include<string.h>
#define MAX 10000

char str[MAX];

int isPalindrome(char *a)
{
int i,flag=1,len=strlen(a);
for(i=0;i<len/2;i++)
if(a!=a[len-1-i])
{
flag = 0;
break;
}
return flag;
}

int checkRev(char a, char b)
{
int i;
char Mirr[21][2]={{'A','A'},{'E','3'},{'H','H'},{'I','I'},
{'J','L'},{'L','J'},{'M','M'},{'O','O'},
{'S','2'},{'T','T'},{'U','U'},{'V','V'},
{'W','W'},{'X','X'},{'Y','Y'},{'Z','5'},
{'1','1'},{'2','S'},{'3','E'},{'5','Z'},
{'8','8'} };
for(i=0;i<21;i++)
if(Mirr[0]==a&&Mirr[1]==b)
return 1;
return 0;
}

int isMirr(char *a)
{
int i,flag=1,len=strlen(a);
for(i=0;i<len/2;i++)
if(!checkRev(a,a[len-1-i]))
{
flag = 0;
break;
}
return flag;
}

void showOut(char *a)
{
int i,j;
i = isPalindrome(a), j = isMirr(a);
if(j==1&&i==0)
printf("%s -- is a mirrored string.\n\n",str);
else if(j==0&&i==1)
printf("%s -- is a regular palindrome.\n\n",str);
else if(i==1&&j==1)
printf("%s -- is a mirrored palindrome.\n\n",str);
else
printf("%s -- is not a palindrome.\n\n",str);
}

void main(void)
{
while(gets(str))
showOut(str);
}[/cpp]

Posted: Fri Jun 13, 2003 7:49 am
by Dominik Michniewski
avoid regular in (regular palindrome)

Best regards
DM

401 WA , pliiiiiiiiiiiiiiiiiizzzzzzzzzzzzzzzzzzzzzzzz help

Posted: Thu Sep 11, 2003 6:24 am
by Riyad
i am having wa in 401 all the time . is there any thing i am missing ???????
i tried a lot of thing , but failed all the time . i have some questions, what will be the out put of the following ??????

MADAM
PANEENAP
I
A
3DDE


HERE IS MY CODE PLIZZZZZZZZZZZZZ HELP ME

Code: Select all

#include<stdio.h>
#include<string.h>

char forward[]="AEHIJLMOSTUVWXYZ12358";
char reverse[]="A3HIJLJMO2TUVWXY5ISEZ8";




int check(char ch,int count ){

	register int i ;
	

	for(i=0;forward[i]!='\0';i++){
		if(ch==forward[i]){
			count=1;
			return i;
		}
		else
			continue;
	
	}

	for(i=0;reverse[i]!='\0';i++){
		if(ch==reverse[i]){
			count=2;
			return i;
		}
		else
			continue;
	
	
	}
	count=0;
	return -1;



}



int check_palindrome(char input[]){
	
	
	register int i , j;
	int flag=1;

	for(i=0,j=strlen(input)-1;j>i;i++,j--){
		if(input[i]==input[j])
			continue;
		else{
			flag=0;
			break;
		}
	
	}

	return flag;


}

int check_mirroredstring(char input[]){
	
	
	register int i , j ;
	int count=0;
	int index;
	
	
	for(i=0,j=strlen(input)-1;i<=j;i++,j--){
		index=check(input[i],count);
		
		if(index==-1){
			return 0;
		}

		else{
		
			if(count==1){
				if(reverse[index]==input[j]){
					continue;
				}
				else{
				

					return 0;
				}
			
			}


			else if(count==2){
				if(forward[index]==input[j]){
					continue;
				}
				else{
				

					return 0;
				}
			}

		}
	
	
	
	}

	return 1;
	

}





int main(){

	int mflag,pflag;
	char input[100];
	
	
	
	while(scanf("%s",input)==1){

		mflag=check_mirroredstring(input);
		pflag=check_palindrome(input);
		
		printf("%s",input);

		if(mflag==0 && pflag==0){
			printf(" -- is not a palindrome.\n\n");
		}
		else if(mflag==0 && pflag==1){
			printf(" -- is a regular palindrome.\n\n");
		}
		else if(mflag==1 && pflag==0){
			printf(" -- is a mirrored string.\n\n");
		}
		else if(mflag==1 && pflag==1){
			printf(" -- is a mirrored palindrome.\n\n");
		}
	
	}
	return 0;
} 

THANX IN ADVANCE , LOOKING FOR U R HELP
Bye
Riyad

401 - WHAT IS HAPPENING ????? PLIZZZZZZZZZZZZZZZ HELP

Posted: Fri Sep 19, 2003 7:47 am
by Riyad
I AM HAVING WA IN THE PROB 401 FOR A LONG TIME . I TRIED DIFFERENT THINGS BUT FAILED . SO HERE IS MY CODE , PLIZZZZZ HELP ME IN MY CODE :

Code: Select all

#include<stdio.h>
#include<string.h>

char forward[]="AEHIJLMOSTUVWXYZ12358";
char reverse[]="A3HILJMO2TUVWXY51SEZ8";




int check(char ch,int &count ){

	register int i ;


	for(i=0;forward[i]!='\0';i++){
		if(ch==forward[i]){
			count=1;
			return i;
		}
		else
			continue;
	
	}

	for(i=0;reverse[i]!='\0';i++){
		if(ch==reverse[i]){
			count=2;
			return i;
		}
		else
			continue;
	
	
	}
	count=0;
	return -1;



}



int check_palindrome(char word[]){
	
	register unsigned int i ;
	int palindrome=0;
	
	for(i=0;i<strlen(word)/2;i++) 
		if(word[i] != word[strlen(word)-i-1]) break; 
	palindrome = ((i >= strlen(word)/2) ? 1: 0); 

	return palindrome;

}

int check_mirroredstring(char input[]){
	
	
	register unsigned int i , j ;
	int count=0;
	int index;
	
	
	for(i=0,j=strlen(input)-1;i<=j;i++,j--){
		index=check(input[i],count);
		
		if(index==-1&& count==0){
			return 0;
		}

		else{
		
			if(count==1){
				if(reverse[index]==input[j]){
					continue;
				}
				else{
				

					return 0;
				}
			
			}


			else if(count==2){
				if(forward[index]==input[j]){
					continue;
				}
				else{
				

					return 0;
				}
			}

		}
	
	
	
	}

	return 1;
	

}





int main(){

	int mflag,pflag;
	char input[100];
	
	freopen("input.in","rt",stdin);
	
	while(scanf("%s",input)==1){
		
		mflag=check_mirroredstring(input);
		pflag=check_palindrome(input);
		
		printf("%s",input);

		if(mflag==0 && pflag==0){
			printf(" -- is not a palindrome.\n\n");
		}
		else if(mflag==0 && pflag==1){
			printf(" -- is a regular palindrome.\n\n");
		}
		else if(mflag==1 && pflag==0){
			printf(" -- is a mirrored string.\n\n");
		}
		else if(mflag==1 && pflag==1){
			printf(" -- is a mirrored palindrome.\n\n");
		}
	
	}
	return 0;
}
Bye
Riyad

Posted: Fri Sep 19, 2003 8:06 am
by Dominik Michniewski
try to avoid word "regular"

Best regards
DM

DID NOT WORK OUT

Posted: Fri Sep 19, 2003 2:46 pm
by Riyad
HEY DOMINIK ,
I TRIED U R WAY BUT DID NOT SUCCEDDED . I GUESS THERE IS SOME THING WRONG WITH MY MIRRORED STRING CHECKING . I LEFT ALONE THE WORD "REGULAR " FROM THE PRINTF() STATEMENT . IS THERE ANY MORE ERRORS .???????????????????? PLIIIIIZZZZZZZZZZZ HELP . EAGERLY WAITING FOR U R HELP .

CHANGES MADE IN THE CODE :
---------------------------------------

BEFORE :-
-----------
else if(mflag==0 && pflag==1){
printf(" -- is a regular palindrome.\n\n");
}

AFTER :-
----------

else if(mflag==0 && pflag==1){
printf(" -- is a palindrome.\n\n");

THANX ONCE AGAIN FOR U HELP .
BYE
RIYAD
}

PE in 401

Posted: Thu Apr 22, 2004 8:32 am
by A1
PE in 401
i got AC but with PE
can any one tell me when the judge reply could give PE for this 401 NO problem.