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 »

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 »

Input:

Code: Select all

(a)
AC output:

Code: Select all

a
Check input and AC output for thousands of problems on uDebug!
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 12543 - Longest Word

Post by uDebug »

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.
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 12543 - Longest Word

Post by uDebug »

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 »

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 »

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 »

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 »

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)”