454 - Anagrams
Moderator: Board moderators
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
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
Happy hunting
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Learning poster
- Posts: 93
- Joined: Sun Jan 12, 2003 3:30 pm
454 - WA
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 ;
}
Sample Input repeated twice:
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 =)
Your output:1T1b5T!1T2b1T1b2T!1T1b1T2b2T!1T3b1T1b1T!3T3b1T!1T3b1T1b1T!5T1*1T
1T1b5T!1T2b1T1b2T!1T1b1T2b2T!1T3b1T1b1T!3T3b1T!1T3b1T1b1T!5T1*1T
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
P.S. Please fix the subject to reflect the correct problem number. Thanks =)
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.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
Alternatively, if your array is too big and is declared in main, it might also give you a Memory Exception.
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]
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]
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
[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
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
[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
WA
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,
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,

454 - Anagrams, inputs???
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
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
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
!
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

Last edited by wolf on Fri Sep 03, 2004 5:32 pm, edited 1 time in total.