12543 - Longest Word

Moderator: Board moderators

tanvir002700
New poster
Posts: 1
Joined: Sun Nov 25, 2012 5:51 pm

12543 - Longest Word

input: ACM Internati-onal120 Collegiate Programming1 Contest.
ac output: internati-onal
raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

Re: 12543 - Longest Word

Deleted
Last edited by raj on Tue Mar 05, 2013 11:53 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12543 - Longest Word

The sample output is international, not International (the first i should be lower case).
Check input and AC output for thousands of problems on uDebug!
raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

Re: 12543 - Longest Word

Deleted
Last edited by raj on Tue Mar 05, 2013 11:53 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12543 - Longest Word

Code: Select all

``Put your code inside the code blocks``
For input:

Code: Select all

``````ASDF123ASDFJKL E-N-D
``````
AC output:

Code: Select all

``````asdfjkl
``````
Check input and AC output for thousands of problems on uDebug!
raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

Re: 12543 - Longest Word

thanks sir.......now its accepted........
but i think u was in hurry because.....

asdfasdfjkl
AKJ88
New poster
Posts: 20
Joined: Wed Feb 13, 2013 10:48 am

Re: 12543 - Longest Word

raj wrote:thanks sir.......now its accepted........
but i think u was in hurry because.....

asdfasdfjkl
No, he wasn't in a hurry!!!
The correct output is what is written. Numbers like space in this problem are separators!
sun_kuet
New poster
Posts: 12
Joined: Wed Mar 27, 2013 4:28 pm

12543 - Longest Word

Thanks
after accepted i removed the code
Last edited by sun_kuet on Thu Mar 28, 2013 11:57 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: CAN't solve WA_12543

Try input:

Code: Select all

``````a b cd E-N-D
``````
AC output:

Code: Select all

``cd``
Check input and AC output for thousands of problems on uDebug!
Angry Bird
New poster
Posts: 21
Joined: Mon Apr 08, 2013 8:38 am

Re: 12543 - Longest Word

Code: Select all

``````#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
char s[1000005],cc[]=" ",a,a1;

int i,j,h;
vector<string>s1,s2;
vector<char>c1,cm;

while(cin>>s)
{
if(!strcmp(s,"E-N-D"))
{
break;
}
else
{
s1.push_back(s);
}
}

for(i=0; i<s1.size(); i++)
{
for(j=0; j<s1[i].size(); j++)
{
c1.push_back(s1[i][j]);
}
c1.push_back(cc[0]);
}

for(h=0; h<c1.size(); h++)
{
if(isalpha(c1[h]))
{
a1=tolower(c1[h]);
cm.push_back(a1);
}
else
{
cm.push_back(c1[h]);
}

}

int count=0,in,max=0,m,ci,ci1;
for(i=0; i<cm.size(); i++)
{
if((((cm[i]>='0')&&(cm[i]<='9'))||(cm[i]==cc[0]))&&(!(((cm[i-1]>='0')&&(cm[i-1]<='9'))||(cm[i-1]==cc[0]))))
{
count=0;
m=i-in;
if(m>max)
{
max=m;
ci=i;
ci1=in;
}
}

else if((!(((cm[i]>='0')&&(cm[i]<='9'))||(cm[i]==cc[0]))))
{
count++;
if(count==1)
{
in=i;
}
}
}

for(int k=ci1; k<ci; k++)
{
cout<<cm[k];
}
return 0;
}

``````
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12543 - Longest Word

Print a newline at the end of the line.
Check input and AC output for thousands of problems on uDebug!
Angry Bird
New poster
Posts: 21
Joined: Mon Apr 08, 2013 8:38 am

Re: 12543 - Longest Word

Getting WA for more time. Plz check it..

Code: Select all

``````    #include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
char s[1000005],cc[]=" ",a,a1;

int i,j,h;
vector<string>s1,s2;
vector<char>c1,cm;

while(cin>>s)
{
if(!strcmp(s,"E-N-D"))
{
break;
}
else
{
s1.push_back(s);
}
}

for(i=0; i<s1.size(); i++)
{
for(j=0; j<s1[i].size(); j++)
{
c1.push_back(s1[i][j]);
}
c1.push_back(cc[0]);
}

for(h=0; h<c1.size(); h++)
{
if(isalpha(c1[h]))
{
a1=tolower(c1[h]);
cm.push_back(a1);
}
else
{
cm.push_back(c1[h]);
}

}

int count=0,in,max=0,m,ci,ci1;
for(i=0; i<cm.size(); i++)
{
if((((cm[i]>='0')&&(cm[i]<='9'))||(cm[i]==cc[0]))&&(!(((cm[i-1]>='0')&&(cm[i-1]<='9'))||(cm[i-1]==cc[0]))))
{
count=0;
m=i-in;
if(m>max)
{
max=m;
ci=i;
ci1=in;
}
}

else if((!(((cm[i]>='0')&&(cm[i]<='9'))||(cm[i]==cc[0]))))
{
count++;
if(count==1)
{
in=i;
}
}
}

for(int k=ci1; k<ci; k++)
{
cout<<cm[k];
}
cout<<endl;

return 0;
}

``````
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12543 - Longest Word

Input:

Code: Select all

`````` son.in-law
``````
AC output:

Code: Select all

``in-law``
Check input and AC output for thousands of problems on uDebug!
Angry Bird
New poster
Posts: 21
Joined: Mon Apr 08, 2013 8:38 am

Re: 12543 - Longest Word

Please brother check my code and remove the wrong part. I can't get the problem. Or give me more sample input-output to get AC.

Code: Select all

``````    #include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
char s[1000005],cc[]=" ",a,a1,CC1[]=".";

int i,j,h;
vector<string>s1,s2;
vector<char>c1,cm;

while(cin>>s)
{
if(!strcmp(s,"E-N-D"))
{
break;
}
else
{
s1.push_back(s);
}
}

for(i=0; i<s1.size(); i++)
{
for(j=0; j<s1[i].size(); j++)
{
c1.push_back(s1[i][j]);
}
c1.push_back(cc[0]);
}

for(h=0; h<c1.size(); h++)
{
if(isalpha(c1[h]))
{
a1=tolower(c1[h]);
cm.push_back(a1);
}
else
{
cm.push_back(c1[h]);
}

}

int count=0,in,max=0,m,ci,ci1;
for(i=0; i<cm.size(); i++)
{
if((((cm[i]>='0')&&(cm[i]<='9'))||(cm[i]==cc[0])||(cm[i]==CC1[0]))&&(!(((cm[i-1]>='0')&&(cm[i-1]<='9'))||(cm[i-1]==cc[0])||(cm[i-1]==CC1[0]))))
{
count=0;
m=i-in;
if(m>max)
{
max=m;
ci=i;
ci1=in;
}
}

else if((!(((cm[i]>='0')&&(cm[i]<='9'))||(cm[i]==cc[0])||(cm[0]==CC1[0]))))
{
count++;
if(count==1)
{
in=i;
}
}
}

for(int k=ci1; k<ci; k++)
{
cout<<cm[k];
}
cout<<endl;

return 0;
}

``````
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12543 - Longest Word

A word is composed of only letters of the alphabet (a-z, A-Z) and may contain one hyphen (-) or more. Why are you testing for digits and space and .? It would be easier to just check if isalpha or - than to test everything else.
Check input and AC output for thousands of problems on uDebug!