Page 1 of 2

12543 - Longest Word

Posted: Sun Nov 25, 2012 6:05 pm
by tanvir002700
input: ACM Internati-onal120 Collegiate Programming1 Contest.
ac output: internati-onal

Re: 12543 - Longest Word

Posted: Wed Feb 20, 2013 10:14 pm
by raj
Deleted

Re: 12543 - Longest Word

Posted: Thu Feb 21, 2013 12:54 am
by brianfry713
The sample output is international, not International (the first i should be lower case).

Re: 12543 - Longest Word

Posted: Thu Feb 21, 2013 10:23 pm
by raj
Deleted

Re: 12543 - Longest Word

Posted: Fri Feb 22, 2013 7:35 pm
by brianfry713

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

Re: 12543 - Longest Word

Posted: Fri Feb 22, 2013 9:49 pm
by raj
thanks sir.......now its accepted........ :D
but i think u was in hurry because.....
the read output should be according to your input... :)

asdfasdfjkl

Re: 12543 - Longest Word

Posted: Fri Feb 22, 2013 10:53 pm
by AKJ88
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!

12543 - Longest Word

Posted: Wed Mar 27, 2013 4:37 pm
by sun_kuet
Thanks
after accepted i removed the code

Re: CAN't solve WA_12543

Posted: Thu Mar 28, 2013 12:44 am
by brianfry713
Try input:

Code: Select all

a b cd E-N-D
AC output:

Code: Select all

cd

Re: 12543 - Longest Word

Posted: Sun Sep 15, 2013 7:38 am
by Angry Bird
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;
}


Re: 12543 - Longest Word

Posted: Tue Sep 17, 2013 9:35 pm
by brianfry713
Print a newline at the end of the line.

Re: 12543 - Longest Word

Posted: Mon Sep 23, 2013 9:54 pm
by Angry Bird
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;
    }



Re: 12543 - Longest Word

Posted: Tue Sep 24, 2013 12:17 am
by brianfry713
Input:

Code: Select all

 son.in-law
AC output:

Code: Select all

in-law

Re: 12543 - Longest Word

Posted: Thu Sep 26, 2013 9:22 pm
by Angry Bird
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;
    }



Re: 12543 - Longest Word

Posted: Fri Sep 27, 2013 11:33 pm
by brianfry713
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.