409 - Excuses, Excuses!

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

Moderator: Board moderators

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

Re: why i got WA in 409 (PLZ help)

Post by brianfry713 » Sat Dec 29, 2012 12:37 pm

there are capitals in the sample output
Check input and AC output for thousands of problems on uDebug!

Kenpachi24
New poster
Posts: 20
Joined: Wed Oct 30, 2013 7:06 pm

Remove

Post by Kenpachi24 » Wed Oct 30, 2013 7:41 pm

Remove
Last edited by Kenpachi24 on Fri Feb 07, 2014 8:41 am, edited 3 times in total.

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

Re: 409 - Excuses, Excuses!

Post by brianfry713 » Thu Oct 31, 2013 9:24 pm

Try input:

Code: Select all

1 2
dog
DoG
This excuse is so good that it contain 0 keywords.
Output should be:

Code: Select all

Excuse Set #1
DoG

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

Kenpachi24
New poster
Posts: 20
Joined: Wed Oct 30, 2013 7:06 pm

Remove

Post by Kenpachi24 » Thu Oct 31, 2013 10:37 pm

Remove
Last edited by Kenpachi24 on Fri Feb 07, 2014 8:42 am, edited 1 time in total.

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

Re: 409 - Excuses, Excuses!

Post by brianfry713 » Tue Nov 05, 2013 10:06 pm

Input:

Code: Select all

2 2
dog
cat
dog dog dog
dog cat
Output should be:

Code: Select all

Excuse Set #1
dog dog dog

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

Kenpachi24
New poster
Posts: 20
Joined: Wed Oct 30, 2013 7:06 pm

Re: 409 - Excuses, Excuses!

Post by Kenpachi24 » Wed Nov 06, 2013 2:52 am

5th try and I have WA:-I appreciate comments and more.

Code: Select all

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
*
* @author OSCAR
*/
public class MAIN {
    public static void main(String[] args) throws IOException{
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String cad[]=new String[21], palabras[]=new String[21], pmayus[]=new String[21], copiexcusas[]=new String[21], excusas[]=new String[21];
        int key, excus, contadores[]=new int[21];
        String linea;
        int caso=1;
        while ((linea=br.readLine())!=null){
            cad=linea.split(" ");
            key=Integer.parseInt(cad[0]);
            excus=Integer.parseInt(cad[1]);
            for (int i=0; i<key; i++){
                palabras[i]=br.readLine();
                pmayus[i]=palabras[i].toUpperCase();
            }
            for (int i=0; i<excus; i++){
                excusas[i]=br.readLine();
                copiexcusas[i]="";
                for (int j=0; j<excusas[i].length(); j++){//[@#".,!?&]
                    if (excusas[i].charAt(j)=='@'|| excusas[i].charAt(j)=='#'||excusas[i].charAt(j)=='"'||excusas[i].charAt(j)=='.'||excusas[i].charAt(j)==','||excusas[i].charAt(j)=='!'||excusas[i].charAt(j)=='?'||excusas[i].charAt(j)=='&'){
                        copiexcusas[i]+=" ";
                    }
                    copiexcusas[i]+=excusas[i].charAt(j);
                }
                copiexcusas[i]=copiexcusas[i].toUpperCase();
            }
            for (int i=0; i<excus; i++){
                cad=copiexcusas[i].split(" ");
                contadores[i]=0;
                for (int j=0; j<key; j++){
                    for (int k=0; k<cad.length; k++){
                        if (cad[k].equals(pmayus[j]))
                            contadores[i]+=1;
                    }
                }
            }
            int mayor=contadores[0];
            for (int i=1; i<excus; i++){
                if (contadores[i]>mayor)
                    mayor=contadores[i];
            }
            System.out.println("Excuse Set #"+caso);
            caso++;
            for (int i=0; i<excus; i++){
                if (contadores[i]==mayor){
                    System.out.println(excusas[i]);
                }
            }
            System.out.println();
        }
    }
}

INPUTS:

Code: Select all

5 3
dog
ate
homework
canary
died
My dog ate my homework.
Can you believe my dog died after eating my canary... AND MY HOMEWORK?
This excuse is so good that it contain 0 keywords.
6 5
superhighway
crazy
thermonuclear
bedroom
war
building
I am having a superhighway built in my bedroom.
I am actually crazy.
1234567890.....,,,,,0987654321?????!!!!!!
There was a thermonuclear war!
I ate my dog, my canary, and my homework ... note outdated keywords?
1 2
dog
DoG
This excuse is so good that it contain 0 keywords.
2 2
dog
cat
dog dog dog
dog cat
OUTPUT:

Code: Select all

Excuse Set #1
Can you believe my dog died after eating my canary... AND MY HOMEWORK?

Excuse Set #2
I am having a superhighway built in my bedroom.
There was a thermonuclear war!

Excuse Set #3
DoG

Excuse Set #4
dog dog dog
Last edited by Kenpachi24 on Fri Feb 07, 2014 8:44 am, edited 1 time in total.

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

Re: 409 - Excuses, Excuses!

Post by brianfry713 » Wed Nov 06, 2013 9:46 pm

Use class Main.

Use the code blocks to post code.

Ask your questions in English.
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: 409 - Excuses, Excuses!

Post by uDebug » Wed Feb 26, 2014 2:46 pm

Kenpachi24 wrote:5th try and I have WA:-I appreciate comments and more.
As brianfry713 suggested, rename your class from "MAIN" to "Main".

Next, try the following input:

Code: Select all

1 2
puma
56789pUMa01234
There are no big cat names in this sentence so should it be printed?
AC Output:

Code: Select all

Excuse Set #1
56789pUMa01234

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: 409 - Excuses, Excuses!

Post by uDebug » Wed Feb 26, 2014 2:56 pm

It would be helpful to know what the exact list of punctuation is that occurs in this problem. From the problem as it appears on UVA, this is what's shown

Code: Select all

SPMamp".,!?&
Not sure what this means, really. So, then looking at the PDF version yields the following 5 characters

Code: Select all

".,!?
But clearly there's more in the test input because just including what's mentioned above, the space character and the digits 0 through 9 still give WA.

I got AC by including everything that was not part of the alphabet (and that's displayed on a typical QWERTY US keyboard). But this isn't neat.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

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

Re: 409 - Excuses, Excuses!

Post by brianfry713 » Thu Feb 27, 2014 12:42 am

You could use isalpha() as All keywords in the keyword list will contain only contiguous lower case alphabetic characters
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: 409 - Excuses, Excuses!

Post by uDebug » Thu Feb 27, 2014 7:10 am

brianfry713 wrote:You could use isalpha() as All keywords in the keyword list will contain only contiguous lower case alphabetic characters
I didn't necessarily think of this function while coding things up. So, thank you.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

Re: 409 - Excuses, Excuses!

Post by jddantes » Fri May 16, 2014 4:18 pm

Why is this WA?

Code: Select all

#include <stdio.h>
#include <string.h>

int main(){

    char buff[2000];
    int cnt = 0;
    while(fgets(buff, 2000, stdin)!=NULL){
        cnt++;
        int k, e;
        sscanf(buff, "%d %d",&k,&e);
        char keylist[k][100];
        int i;
        for(i=0; i<k; i++){
            fgets(keylist[i], 100, stdin);
            keylist[i][strlen(keylist[i]) - 1 ] = 0;
        }

        char excuselist[e][2000];
        int excusecnt[e];
        memset(excusecnt, 0, e*sizeof(int));
        for(i=0; i<e; i++){
            fgets(excuselist[i], 2000, stdin);
        }

        int maxk = 0;
        for(i=0; i<k; i++){
            int j;
            for(j=0; j<e; j++){
                int a;
                for(a=0; a+strlen(keylist[i])<strlen(excuselist[j]);a++){
                    //printf("Comparing %s with %s", keylist[i],excuselist[j]+a);
                    if(!strncasecmp(keylist[i],excuselist[j]+a, strlen(keylist[i]))){

                        excusecnt[j]++;
                        if(excusecnt[j]>maxk){
                            maxk = excusecnt[j];
                        }
                    }

                }
            }
        }/*
        puts("keywords");
        for(i=0; i<k; i++)
            printf("%s\n",keylist[i]);
        puts("excuselist");
        for(i=0;i<e;i++)
            printf("%s",excuselist[i]);
        */

        printf("Excuse Set #%d\n", cnt);
        for(i=0; i<e; i++){
            if(excusecnt[i] == maxk){
                printf("%s", excuselist[i]);
            }
        }
        printf("\n");




    }



    return 0;
}

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

Re: 409 - Excuses, Excuses!

Post by brianfry713 » Fri May 16, 2014 11:44 pm

Try input:

Code: Select all

1 2
a
aa
a a
AC output:

Code: Select all

Excuse Set #1
a a

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

jddantes
Learning poster
Posts: 73
Joined: Sat Mar 08, 2014 8:55 am

Re: 409 - Excuses, Excuses!

Post by jddantes » Sun May 18, 2014 8:31 am

Thanks for the input.
I've updated it, but it's still WA.
Are there words (as in the keys that should be identified) that should be found in the middle of a word ( word in an excuse, separated by spaces)?

Code: Select all

#include <stdio.h>
#include <string.h>

int main(){

    char buff[2000];
    int cnt = 0;
    while(fgets(buff, 2000, stdin)!=NULL){
        cnt++;
        int k, e;
        sscanf(buff, "%d %d",&k,&e);
        char keylist[k][100];
        int i;
        for(i=0; i<k; i++){
            fgets(keylist[i], 100, stdin);
            keylist[i][strlen(keylist[i]) - 1 ] = 0;
        }

        char excuselist[e][2000];
        int excusecnt[e];
        memset(excusecnt, 0, e*sizeof(int));
        for(i=0; i<e; i++){
            fgets(excuselist[i], 2000, stdin);
        }

        int maxk = 0;
        for(i=0; i<k; i++){
            int j;
            //printf("Testing for key %s\n",keylist[i]);
            for(j=0; j<e; j++){
                /*
                int a;
                for(a=0; a+strlen(keylist[i])<strlen(excuselist[j]);a++){
                    //printf("Comparing %s with %s", keylist[i],excuselist[j]+a);
                    if(!strncasecmp(keylist[i],excuselist[j]+a, strlen(keylist[i]))){

                        excusecnt[j]++;
                        if(excusecnt[j]>maxk){
                            maxk = excusecnt[j];
                        }
                    }

                }*/

                int a=0;
                while(*(excuselist[j]+a)!=0){
                    char word[1000];
                    sscanf(excuselist[j]+a, "%s", word);
                    //printf("comparing %s with len %d\n",word,strlen(word));
                    if(!strncasecmp(keylist[i], word, strlen(keylist[i]))){
                        excusecnt[j]++;
                        if(excusecnt[j]>maxk){
                            maxk = excusecnt[j];
                        }
                    }
                    a+=strlen(word)+1;
                }
                /*
                FILE * stream = fmemopen(excuselist[j], strlen(excuselist[j]), "r");

                char word[1000];
                while(fscanf(stream,"%s",word)!=EOF){
                    //printf("Word is %s\n",word);
                    if(!strncasecmp(keylist[i],word,strlen(keylist[i]))){
                        excusecnt[j]++;
                        if(excusecnt[j]>maxk){
                            maxk=excusecnt[j];
                        }
                        printf("ahem\n");
                        printf("Key should be %s\n",keylist[i]);
                        printf("%s matched with %s\n",keylist[i],word);

                    } else {
                        printf("Key shouldd be %s\n",keylist[i]);
                        printf("%s not matched with %s\n",keylist[i],word);
                        printf("again %sh\n",keylist[i]);
                    }
                }

                fclose(stream);
                */
            }
        }/*
        puts("keywords");
        for(i=0; i<k; i++)
            printf("%s\n",keylist[i]);
        puts("excuselist");
        for(i=0;i<e;i++)
            printf("%s",excuselist[i]);
        */

        printf("Excuse Set #%d\n", cnt);
        for(i=0; i<e; i++){
            if(excusecnt[i] == maxk){
                printf("%s", excuselist[i]);
            }
        }
        printf("\n");




    }



    return 0;
}

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

Re: 409 - Excuses, Excuses!

Post by brianfry713 » Tue May 20, 2014 2:59 am

A keyword ``occurs" in an excuse if and only if it exists in the string in contiguous form and is delimited by the beginning or end of the line or any non-alphabetic character or a space.
For input:

Code: Select all

1 2
a
ab
a
AC Output:

Code: Select all

Excuse Set #1
a

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

Post Reply

Return to “Volume 4 (400-499)”