12543 - Longest Word

All about problems in Volume 125. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

12543 - Longest Word

Post by tanvir002700 » Sun Nov 25, 2012 6:05 pm

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

Post by raj » Wed Feb 20, 2013 10:14 pm

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

Post by brianfry713 » Thu Feb 21, 2013 12:54 am

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

Post by raj » Thu Feb 21, 2013 10:23 pm

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

Post by brianfry713 » Fri Feb 22, 2013 7:35 pm

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

Post by raj » Fri Feb 22, 2013 9:49 pm

thanks sir.......now its accepted........ :D
but i think u was in hurry because.....
the read output should be according to your input... :)

asdfasdfjkl

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

Re: 12543 - Longest Word

Post by AKJ88 » Fri Feb 22, 2013 10:53 pm

raj wrote:thanks sir.......now its accepted........ :D
but i think u was in hurry because.....
the read output should be according to your input... :)

asdfasdfjkl
No, he wasn't in a hurry!!! :D
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

Post by sun_kuet » Wed Mar 27, 2013 4:37 pm

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

Post by brianfry713 » Thu Mar 28, 2013 12:44 am

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

Post by Angry Bird » Sun Sep 15, 2013 7:38 am

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;
}


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

Re: 12543 - Longest Word

Post by brianfry713 » Tue Sep 17, 2013 9:35 pm

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

Post by Angry Bird » Mon Sep 23, 2013 9:54 pm

Getting WA for more time. Plz check it.. :evil:

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

Post by brianfry713 » Tue Sep 24, 2013 12:17 am

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

Post by Angry Bird » Thu Sep 26, 2013 9:22 pm

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

Post by brianfry713 » Fri Sep 27, 2013 11:33 pm

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!

Post Reply

Return to “Volume 125 (12500-12599)”