10391 - Compound Words
Moderator: Board moderators
10391 - Compound Words
Please, could somebody post some conflictive inputs and outputs?
Thank you.
Thank you.
-
- Learning poster
- Posts: 63
- Joined: Thu Apr 04, 2002 2:00 am
I get WA every time I send the problem.
My algorithm:
For each word I look for every other word with the root equal to that word, then I get
the tail of that word and I search if that tail exists as a unique word and i check if it is
not the root to avoid false compound words made using the same word twice.
I don't understand what is wrong.
Thank you.
My algorithm:
For each word I look for every other word with the root equal to that word, then I get
the tail of that word and I search if that tail exists as a unique word and i check if it is
not the root to avoid false compound words made using the same word twice.
I don't understand what is wrong.
Thank you.
I think my algorithm is ok, but I got WA.
Can anyone help check my code or give me some sample input?
Can anyone help check my code or give me some sample input?
Code: Select all
for(n=0; gets(w[n]); n++);
for(i=0; i<n; i++)
{
wilen=strlen(w[i]);
for(j=i+1; j<n ;j++)
{ wjlen=strlen(w[j]);
if(wjlen>wilen)
{
for(k=impossible=0; k<wilen; k++)
if(w[j][k]!=w[i][k]) { impossible=1; break;}
if(impossible) break;
for(k=wilen, index=0; k<wjlen; k++) s[index++]=w[j][k];
s[index]='\0';
itemptr=(char *) bsearch(s,w,n,sizeof(w[0]),compare_function);
if(itemptr) printf("%s\n",w[j]);
}
else break;
}
}
My program output:Caesum wrote:eloha, what does your program output for:
a
aa
aaa
aaaa
aaaaa
aaaaaa
Code: Select all
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaa
aaaaa
aaaaaa
aaaa
aaaaa
aaaaaa
aaaaa
aaaaaa
aaaaaa
Code: Select all
aa
aaa
aaaa
aaaaa
aaaaaa
![:(](./images/smilies/icon_frown.gif)
-
- Experienced poster
- Posts: 151
- Joined: Wed Aug 21, 2002 12:07 am
- Location: Seoul, Korea
- Contact:
maybe..
I experienced the same problem today, and solved it by not producing the output directly. I marked the compound words and printed it later in order then I got AC instead of WA.
Maybe your code doesn't guarantee to make output in order, too.
Try![:)](./images/smilies/icon_smile.gif)
Maybe your code doesn't guarantee to make output in order, too.
Try
![:)](./images/smilies/icon_smile.gif)
Re: maybe..
Whinii F. Thank you so much!Whinii F. wrote:I experienced the same problem today, and solved it by not producing the output directly. I marked the compound words and printed it later in order then I got AC instead of WA.
Maybe your code doesn't guarantee to make output in order, too.
Try
I got AC now!
![:D](./images/smilies/icon_biggrin.gif)
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
I got Acc , when I try to solve this problem, but how can I improve efficiency of my code ? Which algorithm can solve this problem with less than 0.5 sec ? I got time 2.1 sec ....
Thanks for explanation
Dominik
Thanks for explanation
Dominik
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)