12543 - Longest Word
Moderator: Board moderators
-
- 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
ac output: internati-onal
Re: 12543 - Longest Word
Deleted
Last edited by raj on Tue Mar 05, 2013 11:53 pm, edited 1 time in total.
-
- 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!
Re: 12543 - Longest Word
Deleted
Last edited by raj on Tue Mar 05, 2013 11:53 pm, edited 1 time in total.
-
- 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
Code: Select all
ASDF123ASDFJKL E-N-D
Code: Select all
asdfjkl
Check input and AC output for thousands of problems on uDebug!
Re: 12543 - Longest Word
thanks sir.......now its accepted........
but i think u was in hurry because.....
the read output should be according to your input...
asdfasdfjkl
but i think u was in hurry because.....
the read output should be according to your input...
asdfasdfjkl
Re: 12543 - Longest Word
No, he wasn't in a hurry!!!raj wrote:thanks sir.......now its accepted........
but i think u was in hurry because.....
the read output should be according to your input...
asdfasdfjkl
The correct output is what is written. Numbers like space in this problem are separators!
12543 - Longest Word
Thanks
after accepted i removed the code
after accepted i removed the code
Last edited by sun_kuet on Thu Mar 28, 2013 11:57 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: CAN't solve WA_12543
Try input:AC output:
Code: Select all
a b cd E-N-D
Code: Select all
cd
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 21
- Joined: Mon Apr 08, 2013 8:38 am
Re: 12543 - Longest Word
Getting WA. Please help me.....
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;
}
-
- 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!
-
- 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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 12543 - Longest Word
Input:AC output:
Code: Select all
son.in-law
Code: Select all
in-law
Check input and AC output for thousands of problems on uDebug!
-
- 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;
}
-
- 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!