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

walking_hell
New poster
Posts: 14
Joined: Tue Sep 24, 2013 4:35 pm

uva 12543

Post by walking_hell » Fri Oct 04, 2013 1:24 am

Need your help for fixing my bug...thank u

Code: Select all

#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
    char word[100],save[100];
    word[0]='\0';
    int lenprev=0,lennew,count;
    while(strcmp(word,"E-N-D")!=0)
    {
        count=0;
        while(1)
        {
            word[count]=getchar();
            if(word[count]=='(')
            {
                while((word[count]=getchar())!=')');
                word[count]='\0';
                break;

            }
            if((word[count]>='a'&& word[count]<='z')||(word[count]>='A'&& word[count]<='Z')||word[count]=='-')
            count++;

            else break;

        }

        word[count]='\0';
        if(!strcmp(word,"E-N-D"))
        break;
        lennew=strlen(word);
        if(lennew>lenprev)
        {
            lenprev=lennew;
            strcpy(save,word);

        }



    }
    for(count=0;count<lenprev;count++)
    printf("%c",tolower(save[count]));

    return 0;

}

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

Re: uva 12543

Post by brianfry713 » Tue Oct 08, 2013 12:47 am

Input:

Code: Select all

(a)
AC output:

Code: Select all

a
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 12543 - Longest Word

Post by uDebug » Mon Apr 14, 2014 8:23 am

Angry Bird wrote: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.
Input:

Code: Select all

`~1!2@3#4$5%6^7&8*9(0)_notCorrect=+[{]}\\|;:'\",<.>/? correctAnswer E-N-D
AC Output:

Code: Select all

correctanswer
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 12543 - Longest Word

Post by uDebug » Mon Apr 14, 2014 8:24 am

brianfry713,
Thanks for the great test cases!
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

moudud99
New poster
Posts: 28
Joined: Fri Feb 08, 2013 1:40 pm

Re: 12543 - Longest Word

Post by moudud99 » Sun Feb 15, 2015 8:59 am

I am getting PE.do i need to remove new line from end of output? shouldn't all letters be small in output?
Thanks in advance.

Code: Select all

do not print any space and always print a new line at the END!
Last edited by moudud99 on Mon Mar 02, 2015 8:15 pm, edited 1 time in total.

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

Re: uva 12543

Post by brianfry713 » Wed Feb 18, 2015 12:17 am

brianfry713 wrote:Input:

Code: Select all

(a)
AC output:

Code: Select all

a
Check input and AC output for thousands of problems on uDebug!

moudud99
New poster
Posts: 28
Joined: Fri Feb 08, 2013 1:40 pm

Re: 12543 - Longest Word

Post by moudud99 » Fri Feb 20, 2015 7:15 am

should I give a newline or not?

my code gives a single 'a' and a newline.
and when I remove that newline my code gets WA.

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 20, 2015 9:16 pm

There should always be a newline char at the end of the last line.

Input:

Code: Select all

(a E-N-D
Don't print a space.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 125 (12500-12599)”