Page 2 of 2

uva 12543

Posted: Fri Oct 04, 2013 1:24 am
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;

}

Re: uva 12543

Posted: Tue Oct 08, 2013 12:47 am
by brianfry713
Input:

Code: Select all

(a)
AC output:

Code: Select all

a

Re: 12543 - Longest Word

Posted: Mon Apr 14, 2014 8:23 am
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

Re: 12543 - Longest Word

Posted: Mon Apr 14, 2014 8:24 am
by uDebug
brianfry713,
Thanks for the great test cases!

Re: 12543 - Longest Word

Posted: Sun Feb 15, 2015 8:59 am
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!

Re: uva 12543

Posted: Wed Feb 18, 2015 12:17 am
by brianfry713
brianfry713 wrote:Input:

Code: Select all

(a)
AC output:

Code: Select all

a

Re: 12543 - Longest Word

Posted: Fri Feb 20, 2015 7:15 am
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.

Re: 12543 - Longest Word

Posted: Fri Feb 20, 2015 9:16 pm
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.