409 - Excuses, Excuses!
Moderator: Board moderators
-
- 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)
there are capitals in the sample output
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 20
- Joined: Wed Oct 30, 2013 7:06 pm
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 409 - Excuses, Excuses!
Try input:
Output should be:
Code: Select all
1 2
dog
DoG
This excuse is so good that it contain 0 keywords.
Code: Select all
Excuse Set #1
DoG
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 20
- Joined: Wed Oct 30, 2013 7:06 pm
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 409 - Excuses, Excuses!
Input:Output should be:
Code: Select all
2 2
dog
cat
dog dog dog
dog cat
Code: Select all
Excuse Set #1
dog dog dog
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 20
- Joined: Wed Oct 30, 2013 7:06 pm
Re: 409 - Excuses, Excuses!
5th try and I have WA:-I appreciate comments and more.
INPUTS:
OUTPUT:
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();
}
}
}
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
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 409 - Excuses, Excuses!
Use class Main.
Use the code blocks to post code.
Ask your questions in English.
Use the code blocks to post code.
Ask your questions in English.
Check input and AC output for thousands of problems on uDebug!
Re: 409 - Excuses, Excuses!
As brianfry713 suggested, rename your class from "MAIN" to "Main".Kenpachi24 wrote:5th try and I have WA:-I appreciate comments and more.
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?
Code: Select all
Excuse Set #1
56789pUMa01234
Re: 409 - Excuses, Excuses!
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
Not sure what this means, really. So, then looking at the PDF version yields the following 5 characters
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.
Code: Select all
SPMamp".,!?&
Code: Select all
".,!?
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 409 - Excuses, Excuses!
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!
Re: 409 - Excuses, Excuses!
I didn't necessarily think of this function while coding things up. So, thank you.brianfry713 wrote:You could use isalpha() as All keywords in the keyword list will contain only contiguous lower case alphabetic characters
Re: 409 - Excuses, Excuses!
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 409 - Excuses, Excuses!
Try input:AC output:
Code: Select all
1 2
a
aa
a a
Code: Select all
Excuse Set #1
a a
Check input and AC output for thousands of problems on uDebug!
Re: 409 - Excuses, Excuses!
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)?
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 409 - Excuses, Excuses!
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:AC Output:
For input:
Code: Select all
1 2
a
ab
a
Code: Select all
Excuse Set #1
a
Check input and AC output for thousands of problems on uDebug!