10391 - Compound Words
Moderator: Board moderators
10391 - Why WA ???
THis is my code for problem 10391
[pascal]
Program Problema_A(Input, Output);
Var
Conta, I, Temp, Conta2: LongInt;
Words: Array[1..120000] Of String;
Function Procurar(N: String): LongInt;
Var
I, J, A: Integer;
Begin
I:=1;
J:=Conta;
While (I<J) Do
Begin
A:=(I+J) Div 2;
If N<=Words[A] Then
J:=A
Else
I:=A+1;
End;
If N=Words Then
Procurar:=I
Else
Procurar:=0;
End;
Procedure GetData;
Var X, Y: LongInt;
Parte1, Parte2, Parte3 :String;
Begin
Repeat
Inc(Conta);
ReadLn(Input, Words[Conta]);
Until Eof(Input);
For I:=1 To Conta Do
Begin
Temp:=Length(Words);
Conta2:=I;
Repeat
Inc(Conta2);
X:=Pos(Words, Words[Conta2]);
If (X=1) Then
Begin
Parte1:=Words[Conta2];
Parte2:=Words;
Parte3:=Copy(Words[Conta2], Temp+1, Length(Words[Conta2]));
Y:=Procurar(Parte3);
If Not (Y=0) Then
WriteLn(Output, Parte1);
End;
Until Not (X=1);
End;
End;
BEGIN
GetData;
END.
[/pascal]
Why WA???
It result for the example.... and much more.
[pascal]
Program Problema_A(Input, Output);
Var
Conta, I, Temp, Conta2: LongInt;
Words: Array[1..120000] Of String;
Function Procurar(N: String): LongInt;
Var
I, J, A: Integer;
Begin
I:=1;
J:=Conta;
While (I<J) Do
Begin
A:=(I+J) Div 2;
If N<=Words[A] Then
J:=A
Else
I:=A+1;
End;
If N=Words Then
Procurar:=I
Else
Procurar:=0;
End;
Procedure GetData;
Var X, Y: LongInt;
Parte1, Parte2, Parte3 :String;
Begin
Repeat
Inc(Conta);
ReadLn(Input, Words[Conta]);
Until Eof(Input);
For I:=1 To Conta Do
Begin
Temp:=Length(Words);
Conta2:=I;
Repeat
Inc(Conta2);
X:=Pos(Words, Words[Conta2]);
If (X=1) Then
Begin
Parte1:=Words[Conta2];
Parte2:=Words;
Parte3:=Copy(Words[Conta2], Temp+1, Length(Words[Conta2]));
Y:=Procurar(Parte3);
If Not (Y=0) Then
WriteLn(Output, Parte1);
End;
Until Not (X=1);
End;
End;
BEGIN
GetData;
END.
[/pascal]
Why WA???
It result for the example.... and much more.
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
Read the previous thread on this problem. Your program doesn't deal correctly with Caesums input.
There are two errors (although they won't keep you from AC, I think):
- Conta is not initialised;
- Conta2 can get bigger than Conta and point beyond the last element of Words[].
Parta2 is assigned but never used, so get rid of it.
Your program structure is a mess. Variables are 'randomly' declared global or local, without any reason. The name GetData is misleading: besides reading the input, it processes it and produces the output. Either put the whole thing into the main program, or make three procedures: GetData, FindCompoundWords and WriteOutput, or something of the sort. Also don't mix Spanish(?) and English if you want other people to understand your code.
... I should realy contain myself by not being too patronising. Sorry for that, it's stronger than me...
There are two errors (although they won't keep you from AC, I think):
- Conta is not initialised;
- Conta2 can get bigger than Conta and point beyond the last element of Words[].
Parta2 is assigned but never used, so get rid of it.
Your program structure is a mess. Variables are 'randomly' declared global or local, without any reason. The name GetData is misleading: besides reading the input, it processes it and produces the output. Either put the whole thing into the main program, or make three procedures: GetData, FindCompoundWords and WriteOutput, or something of the sort. Also don't mix Spanish(?) and English if you want other people to understand your code.
... I should realy contain myself by not being too patronising. Sorry for that, it's stronger than me...

-
- New poster
- Posts: 43
- Joined: Mon Oct 13, 2003 4:54 pm
- Location: Mexico
- Contact:
10391 .- Why WA?
This is my program , I got Wa, why?
Hint
Code: Select all
Accepted
Code: Select all
Input
gera
geraaa
gerardo
rdo
Output
gerardo
-
- New poster
- Posts: 30
- Joined: Mon Jun 19, 2006 10:37 pm
- Contact:
10391
Code: Select all
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
vector<string> v,r;
string s;
while (getline(cin,s))
{
v.push_back(s);
}
for (int i=0;i<v.size();i++)
{ string d;
d=v[i];
for (int t=0;t<v.size();t++)
for (int j=0;j<v.size();j++)
if(d==v[t]+v[j])
r.push_back(d);
}
sort(r.begin(),r.end());
for (int k=0;k<r.size();k++)
cout<<r[k]<<endl;
return 0;
}
win
-
- New poster
- Posts: 30
- Joined: Mon Jun 19, 2006 10:37 pm
- Contact:
-
- New poster
- Posts: 4
- Joined: Sat Sep 16, 2006 9:55 am
why TLE .......
Can someone tell me.. why i am getting TLE.....
Code: Select all
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
bool cmp(string s1,string s2){
if(s2.size()<s1.size()){
if(s2==s1.substr(0,s2.size())) return true;
return false;
}
return false;
}
int main(){
long int l,i;
string s;
vector<string> v;
vector<string>::iterator j,p;
vector<int> y;
while(cin>>s){
v.push_back(s);
y.push_back(1);
}
for(i=0;i<v.size()-1;i++){
j=search_n(v.begin()+i+1,v.end(),1,v[i],cmp);
while(j<v.end()){
if(y[j-v.begin()]==1){
p=search_n(v.begin(),v.end(),1,v[j-v.begin()].substr(v[i].size()));
if(p!=v.end()){
cout<<*j<<endl;
y[j-v.begin()]=0;
}
}
j=search_n(j+1,v.end(),1,v[i],cmp);
}
}
return 0;
}
-
- New poster
- Posts: 37
- Joined: Wed Oct 03, 2007 10:42 am
Re: 10391 - Compound Words
I am getting TLE. please help me.
I use a string array to store all the string.
Then I take string and concate every string with it and binary search from the array to check whether
compound word is present or not. If present output it.
Why I am getting TLE.
My code is given bellow.
Thanks everybody.
I use a string array to store all the string.
Then I take string and concate every string with it and binary search from the array to check whether
compound word is present or not. If present output it.
Why I am getting TLE.
My code is given bellow.
Code: Select all
cut after acc
thnks Jan. I have used Trie and got it accepted
Last edited by alamgir kabir on Tue Apr 21, 2009 9:18 pm, edited 1 time in total.
Re: 10391 - Compound Words
i sloved this problem but i can not remove WA.
i consider all given input & output but my program gave WA
please give me some critical input-output
thanks in advance
i consider all given input & output but my program gave WA
please give me some critical input-output
thanks in advance
10391 - Compound Words
How many letters may stay in a word at most???????
It is not mentioned in this problem.
It is not mentioned in this problem.