Page 2 of 14

Posted: Mon Jun 24, 2002 8:46 pm
by udcp
I got it ACCEPTED!!!!!!! :D
The only change I made was changed
' int main(int argv, char *argc[]) '
to
'void main()'

But.. Can't we actually use command line args while submitting our program?? :-?

Posted: Mon Jun 24, 2002 9:22 pm
by 10153EN
What do mean by *command line args*?

I also write the programs as
int main(int argc, char **argv)
and it's OK~

Posted: Tue Jun 25, 2002 12:21 pm
by cyfra
Hi!

udcp: what mail client do you use ??

Maybe the problem is there because I don't believe that you couldn't get your program AC without any changes while other persons could...

That's the next strange case in Online Judge history :wink:

Posted: Sat Jul 13, 2002 10:40 pm
by Subeen
the following code of mine also got W.A. :(
can anyone find the bug??? :wink:

Code: Select all

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

char in[50];

void check()
{
   char a1[] = {'A', 'E', 'H', 'I', 'J', 'L', 'M', 'O', 'S', 'T', 'U', 'V', 'W',
   'X', 'Y', 'Z', '1', '2', '3', '5', '8'};
   char a2[] = {'A', '3', 'H', 'I', 'L', 'J', 'M', 'O', '2', 'T', 'U', 'V', 'W',
   'X', 'Y', '5', '1', 'S', 'E', 'Z', '8'};

   int len = strlen(in);
   int i, j, k, half;
   int pdrome = 1, mirror = 1;

   half = len / 2;
   for(i=0, j=len-1; i<half; i++, j--)
   {
   	if(in[i]!=in[j]) pdrome = 0;
      for(k=0; k<21; k++)
      {
      	if(in[i]==a1[k])
         {
           	if(in[j]!=a2[k])
            {
              	mirror = 0;
               break;
            }
         }
      }
   }

   if(len%2==1 && mirror)
   {
      mirror = 0;
   	i = half;
      for(k=0; k<21; k++)
      {
      	if(in[i]==a1[k])
         {
         	if(a1[k]==a2[k])
            	mirror = 1;
            break;
         }
      }
   }

   if(pdrome && mirror)
   	printf("%s -- is a mirrored palindrome.\n\n", in);
   else if(pdrome)
   	printf("%s -- is a regular palindrome.\n\n", in);
   else if(mirror)
   	printf("%s -- is a mirrored string.\n\n", in);
   else
      printf("%s -- is not a palindrome.\n\n", in);
}

void main()
{
   while(scanf("%s", in)==1)
   {
   	check();
   }
}
I couldn't find the bug, but solved it using another approach.

Posted: Mon Jul 15, 2002 5:18 pm
by kuasha
I dont understand why this simple problem cause so much problem. I have tried almost everything I can imagine. But the WA is not leaving me.

Posted: Mon Jul 15, 2002 6:50 pm
by Melon Melon
mm...
yes..i ve tried subeen's one...but still cant get where get wrong...
and for udcp's one..
i ve sent to the judge...it got accepted..
....
so...strange..for both..-__-"

401 - complie error [pascal] :-?

Posted: Mon Aug 05, 2002 11:07 pm
by masti
I have some problems with this code. When I'am compiling it under Turbo Pascal everything is Ok but in Free Pascal I get errors. Can anyone help me?
**********************************************************
program palindromes(input,output);


const
pali = ' -- is a regular palindrome.';
mstrin = ' -- is a mirrored string.';
mpali = ' -- is a mirrored palindrome.';
none = ' -- is not a palindrome.';

var
P:array [1..42] of char;
s:string;
i:integer;


procedure check;

label
j1,j2,j3;

var
i,n:integer;
l:integer;
is:boolean;

begin
l:=length(s);
n:=l div 2;
is:=true;
for i:=1 to n do
if s <> s[l-i+1] then
begin
is:=false;
goto j1;
end;
j1:
if is then
begin
for i:=1 to n do
if s <> P[ord(s[l-i+1])-48] then
begin
is:=false;
goto j2;
end;
j2:
if is then
writeln(output,s,mpali)
else
writeln(output,s,pali);
end
else
begin
is:=true;
for i:=1 to n do
if s <> P[ord(s[l-i+1])-48] then
begin
is:=false;
goto j3;
end;
j3:
if is then
writeln(s,mstrin)
else
writeln(s,none);
end;
end;

begin
P[1]:='1';
P[2]:='S';
P[3]:='E';
P[5]:='Z';
P[8]:='8';
P[17]:='A';
P[21]:='3';
P[24]:='H';
P[25]:='I';
P[26]:='L';
P[28]:='J';
P[29]:='M';
P[31]:='O';
P[35]:='2';
P[36]:='T';
P[37]:='U';
P[38]:='V';
P[39]:='W';
P[40]:='X';
P[41]:='Y';
P[42]:='5';


while not eof(input) do
begin
readln(input,s);
check;
writeln(output);
end;
end.[/pascal]

got?

Posted: Sat Aug 10, 2002 1:37 pm
by liusu
You'd better not use 'goto' sentence.it's not a good ideal.I think if there is no 'goto',the error will go away.

good luck.

Posted: Sat Aug 10, 2002 2:52 pm
by xenon
Some remarks:

1. Use Pascal button to format your code. This makes it much more readable.

2. Your program compiles perfectly with my free pascal compiler, but according to the standard, when using labels within a procedure, first declare the variables, then declare the labels. Like this:
[pascal]procedure bla(bla:bla);
var
bla:bla;
label
bla;
begin
bla;
bla:
bla;
end;[/pascal]
And NOT
[pascal]procedure bla(bla:bla);
label
bla;
var
bla:bla;
begin
bla;
bla:
bla;
end;[/pascal]
The Judge's Pascal compiler is very strict, so that could be the problem.

3. I'm not too manic about avoiding GOTO statements, but this is a little too much. Use the break statement if you want to leave a loop prematurely:
[pascal]for bla:=bla to bla do begin
if (bla=bla) then break;
bla;
end;[/pascal]
Instead of:
[pascal]for bla:=bla to bla do begin
if (bla=bla) then goto bla;
bla;
end;
bla:[/pascal]
Of course this doesn't work if you want to break out of more then one level of looping. But if you need that, most likely there is something messed up with your algorithm, and you can better redesign the program.

Hope it helps,
-xenon

you can do like this:

Posted: Sat Aug 10, 2002 5:29 pm
by liusu
you can use the 'while' :

[pascal]flag:=true;
i:=xx;
while (i<xxx) and flag do
begin
xxxx;
if xxx then flag:=false
else inc(i);
end;[/pascal]

I used it and pass this problem.good luck. :wink:

Posted: Sun Aug 11, 2002 9:41 pm
by masti
thanks for help I will try redesing my problem as you said

problem in 401

Posted: Tue Oct 22, 2002 9:45 pm
by ashfaq_csdu
hi,
I am getting WA for 6 times in this problem. I think I am missing something.
Q1. What happened if the string is of only 1 letter?
Q2. Can the string be of small letters?
Q3. If there is no reverse then what happens? Will it say this is not mirrored string or mirrored palindrome? Or will it ignore it?

Please help me.

Ashfaq

401 WA: Help mee...

Posted: Wed Nov 20, 2002 4:04 pm
by Angel
first debug ......... then run it : see the diffrence.........plz help me.......







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

int palindrome();
int mirror();
char chart(char ch);
char A[22],B[22];
char C[14]={'A','H','I','M','O','T','U','V','W','X','Y','1','8'};
char D[10]={'J','L','S','2','Z','5','3','E'};

void main(void)
{

while(1)
{
int palin=0,mir=0;
gets(A);
palin=palindrome();
mir=mirror();
if(palin==1&&mir==1){printf("%s - is a mirrored palindrome.\n",A);printf("\n");}
else if(palin==1&&mir!=1){printf("%s - is a regular palindrome.\n",A);printf("\n");}
else if(palin!=1&&mir==1){printf("%s - is a mirrored string.\n",A);printf("\n");}
else if(palin!=1&&mir!=1){printf("%s - is not a palindrome.\n",A);printf("\n");}

memset(A,0,sizeof(A));
memset(B,0,sizeof(B));
}
}

int mirror()
{
int flag,flag2,a,c,d,count=0,count2=0,len;
char ch;
len=strlen(A);
for(a=0;A[a];a++)
{
if(flag==0)break;

for(c=0;c<13;c++)
{
if(A[a]==C[c])
{
count++;
if(A[a]==A[len-a-1])
flag=1;
else flag=0;
}
if(flag==0)break;
}
}



for(a=0;A[a];a++)
{
if(flag2==0)break;
for(d=0;d<9;d++)
{
if(D[d]==A[a])
{
count2++;
ch=A[a];
ch=chart(ch);
if(A[len-1-a]==ch)
{
flag2=1;
}
else{flag2=0;break;}
}
}
}

if(flag==1&&flag2==1)return 1;
if(count==0&&flag2==1)return 1;
if(flag==1&&count2==0)return 1;
else return 0;
}

int palindrome()
{
int b=0,cmp,a,len;
len=strlen(A);
strcpy(B,A);
for(a=len-1;a>=0;a--)B[b++]=A[a];
cmp=strcmp(A,B);
if(cmp==0)return 1;
else return 0;
}

char chart(char ch)
{
if(ch=='J')ch='L';
else if(ch=='L')ch='J';
else if(ch=='3')ch='E';
else if(ch=='E')ch='3';
else if(ch=='S')ch='2';
else if(ch=='2')ch='S';
else if(ch=='5')ch='Z';
else if(ch=='Z')ch='5';

return ch;
}

Posted: Wed Nov 20, 2002 4:56 pm
by Dominik Michniewski
no "regular" word in output ....

Best regards
Dominik

Posted: Thu Nov 21, 2002 2:10 pm
by rakeb
i think you done too much to chek the mirror
just define normal and mirrored charecters in two strings
[cpp]
char Char[22]="AEHIJLMOSTUVWXYZ12358";
char Revers[22]="A3HILJMO2TUVWXY51SEZ8";

[/cpp]
then build another string b[100] by the mirrored charecters of original charecters. then compare them, if they are same then the string is mirrored.
[cpp]

for(i=0,j=n-1;i<n;i++,j--){
b=search(m[j]);
}
b[n]='\0';
if ( !strcmp(m,b))return 1;
[/cpp]
in the search function just return the corrosponding mirrored charecter
by searching Char and Revers string