Page 2 of 7

Posted: Mon Jun 02, 2003 7:58 am
by Dominik Michniewski
I made one modification - I remember not only distinct phrases, but phrases like "a = a" too.... and got Acc after rejudgement ... So I think, that my last post is correct.

Happy hunting
DM

454 - WA

Posted: Fri Jun 20, 2003 11:20 am
by Almost Human
I couldn't figure out why I got WA .... Please give me some special input and output ....

Code: Select all

#include <ctype.h>
#include <stdio.h>

int main ( void )
{
  char input[60000] , ToBePrinted ;
  unsigned i ; int counter , j ;

/*  freopen ( "445.in" , "r" , stdin ) ;
  freopen ( "445.out" , "w" , stdout ) ;*/

  while ( scanf ( "%[^\n!]" , input ) != EOF )
  {
	 fgetc ( stdin ) ;

	 for ( i = counter = 0 ; input[i] ; i ++ )
	 {
		if ( isdigit ( input[i] ) )
		  counter += ( input[i] -'0' ) ;
		else
		{
		  if ( input[i] == 'b' ) ToBePrinted = 32 ;
		  else ToBePrinted = input[i] ;

		  for ( j = 0 ; j < counter ; j ++ )
			 printf ( "%c" , ToBePrinted ) ;

		  counter = 0 ;
		}
	 }
	 printf ( "\n" ) ;
  }

  return 0 ;
}

Posted: Mon Aug 04, 2003 8:31 pm
by Junayeed
Please help me with some mutiple test cases.
Thanks.

Posted: Thu Aug 07, 2003 2:09 am
by UFP2161
Sample Input repeated twice:
1T1b5T!1T2b1T1b2T!1T1b1T2b2T!1T3b1T1b1T!3T3b1T!1T3b1T1b1T!5T1*1T

1T1b5T!1T2b1T1b2T!1T1b1T2b2T!1T3b1T1b1T!3T3b1T!1T3b1T1b1T!5T1*1T
Your output:

Code: Select all

T TTTTT
T  T TT
T T  TT
T   T T
TTT   T
T   T T
TTTTT*T
TTTTT*T
T TTTTT
T  T TT
T T  TT
T   T T
TTT   T
T   T T
TTTTT*T
There should be a newline between to two test cases, instead you're somehow printing the last line again. (This doesn't always happen though, as in putting the second example after the above two produces a blank line, but putting that second example again doesn't...).

P.S. Please fix the subject to reflect the correct problem number. Thanks =)

Posted: Thu Aug 07, 2003 2:11 am
by UFP2161
Unlike the sample input, I think the real input has uppercase letters as well, which should be considered different from their lowercase counterparts. That was the only difference between my WA and AC.

Posted: Thu Aug 07, 2003 2:25 am
by UFP2161
zsepi wrote:the whole issue is that I am not getting WA, but RE, which is really upsetting after X time spent debugging that prog and finally got it working
Without your code, the only thing I can ask is are you checking for uppercase letters as well? Because if you just assume that lowercase letters are being used as in the sample input, you might be doing something trying to use an index like ['A' - 'a'] which is a negative number. The size of the array would thus not matter if that were the case.

Alternatively, if your array is too big and is declared in main, it might also give you a Memory Exception.

Posted: Fri Oct 03, 2003 5:47 am
by jeff1999
I was hoping that you guys could give me a hand. I am getting "WA" everytime, and my guess is that there is some ambiguity I am not accounting for in the problem statement. Could someone please point out the flaw in the following code?
Many thanks,
-Jeff

[cpp]// 454 - Anagrams

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

struct Word
{
char line[200];
char orig[200];
};

int c_cmp(const void * a, const void * b)
{
return (int)(*((char*)a) - *((char*)b));
}

int w_cmp(const void * a, const void * b)
{
Word * w1 = (Word*)a, * w2 = (Word*)b;
return strcmp(w1->orig, w2->orig);
}

void strscpy(char * dst, char * src) // strcpy but skip if < 0x20
{
while (*src)
{
if (*src > ' ')
{
*dst = *src;
++dst;
}
++src;
}
*dst = 0;
}

int main(int argc, char ** argv)
{
Word words[200];
int i = 0, j, n = 1;
while (n && gets(words.orig) && strlen(words.orig) > 0)
{
strscpy(words.line, words.orig);
qsort(words.line, strlen(words.line), sizeof(char), c_cmp);
++i;
}
qsort(words, i, sizeof(Word), w_cmp);
n = i;
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (strcmp(words.line, words[j].line) == 0)
{
printf("%s = %s\n", words.orig, words[j].orig);
}
}
}
return 0;
}[/cpp]

Posted: Fri Oct 03, 2003 5:53 am
by jeff1999
Nevermind, after experimenting with something, I got an accepted (With PE). I wrapped my everything after and including my while loop in main inside of a
[cpp]
while (!feof(stdin))
{
i = 1;
// rest of code went here
}
[/cpp]

Nowhere in the problem does it state that their will be multiple lists of anagrams though, yet it seems that their were indeed multiple lists.
Again, my apologies for the large (and unnecessary) post above.
-Jeff

Posted: Fri Oct 03, 2003 6:14 am
by jeff1999
Nevermind, after experimenting with something, I got an accepted (With PE). I wrapped my everything after and including my while loop in main inside of a
[cpp]
while (!feof(stdin))
{
i = 1;
// rest of code went here
}
[/cpp]

Nowhere in the problem does it state that their will be multiple lists of anagrams though, yet it seems that their were indeed multiple lists.
Again, my apologies for the large (and unnecessary) post above.
-Jeff

Posted: Tue Jul 20, 2004 12:05 pm
by InOutMoTo
my approach is :

1: Get all input and sort them. (using qsort + strcmp)
2: store all data (since ASCII range is 0-255) in array[MAXSIZE][300]
3:
[c]for(i = 0; i < input; i++)
for(j = i+1; j < input; j++)
if(check(data, data[j]) == YES)
output(input, input[j]);[/c]

best regards!

WA

Posted: Sun Aug 15, 2004 9:40 am
by Guest
Hello,
I'm getting WA for this problem though my code seems to give correct ouput for all sample data i could find. Can anyone give me some more sample i/o?
Thank you,

Edited: 21.08.2004
Comment: I've got AC, :D

454 - Anagrams, inputs???

Posted: Tue Aug 31, 2004 7:11 pm
by Junayeed
Can anyone tell me how the inputs will be for this problem.
As it is multiple input problem.Will it look like this:

6

carthorse
horse
horse cart
i do not know u
ok i now donut
orchestra

3

aaa
aaa
aaa

What will be the output for the 2nd input. Please help me.

Junayeed

454 Invalid memory reference

Posted: Fri Sep 03, 2004 11:35 am
by wolf
Hi !
My code have Invalid memory reference. Where is the bug in my code ?

[cpp]
//removed for saving the space in the topic
[/cpp]

Thx for future help :-D !

Posted: Fri Sep 03, 2004 1:30 pm
by Junayeed
Use array lenght of 500 instead of 255.
Hope this will work.
Best of luck.

Junayeed

Posted: Fri Sep 03, 2004 5:31 pm
by wolf
Thanx :-D but this is WA now. I need some I/O.

[cpp]
/*removed, AC*/
[/cpp]