Page 1 of 1

11233 - Deli Deli

Posted: Sun Jun 15, 2008 9:27 pm
by palash
I tried this problem to solve but every time i got WA. but why i can't understand . Please anybody help me. here is me code

Code: Select all


At last ACC. i think i should be more watchful about code. :roll: 


Re: 11233 - Deli Deli

Posted: Sat Jun 28, 2008 1:51 am
by palash
Is it a multiple test case problem?
please give me some test input and output...

Re: 11233 - Deli Deli

Posted: Sat Jun 28, 2008 7:38 am
by Chirag Chheda
it is not a multiple input problem..

Re: 11233 - Deli Deli

Posted: Sun Aug 30, 2009 9:14 am
by fushar
just create a map<string, string> representing the irregular plural forms of the words in the description.

11233 Deli Deli - Runtime Error. please help

Posted: Mon Jan 17, 2011 6:34 pm
by Shiba
i've got AC with the same alogorithm in C++. But in case of Java there is always RE :( . can anyone plz help me. where is my fault??

Code: Select all

import java.util.Scanner;

class Main {
    static boolean vowel (char ch) {
        if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return true;
        return false;
    }
    public static void main (String args[]) {
        Scanner input = new Scanner(System.in);
        int L, N, i, j, k;
        String irregular[] = new String [25];
        String plural[] = new String [25];
        String word[] = new String [25];

        L = input.nextInt();
        N = input.nextInt();
        
        for(i=0; i<L; i++) {
            irregular[i] = input.next();
            plural[i] = input.next();
        }
        for(i=0; i<N; i++)
            word[i] = input.next();

        for(i=0; i<N; i++) {
            for(k=0; k<L; k++) {
                if(word[i].compareTo(irregular[k]) == 0) {
                    System.out.println(plural[k]);
                    break;
                }
            }
            if(k == L) {
                int len = word[i].length();
                if(word[i].charAt(len-1) == 'y' && len > 1 && !vowel(word[i].charAt(len-2))) {
                    for(j=0; j<len-1; j++)
                        System.out.print(word[i].charAt(j));
                    System.out.println("ies");
                }
                else if (word[i].charAt(len-1) == 'o' || word[i].charAt(len-1) == 's' || word[i].charAt(len-1) == 'x')
                    System.out.println(word[i] + "es");
                else if (word[i].charAt(len-1) == 'h' && len > 1) {
                    if(word[i].charAt(len-2) == 'c' || word[i].charAt(len-2) == 's')
                        System.out.println(word[i] + "es");
                    else
			System.out.println(word[i] + "s");
                }
                else
                    System.out.println(word[i] + "s");
            }
        }
    }
}

Re: 11233 - Deli Deli

Posted: Tue Mar 18, 2014 9:20 am
by uDebug
Here's some input / output that I found useful during testing / debugging.

Input:

Code: Select all

3 20
rice rice
spaghetti spaghetti
octopus octopi
rice
lobster
spaghetti
strawberry
octopus
peach
turkey
boy
buy
bay
grey
biy
too
vex
brash
nexus
chaste
park
label
snake
AC Output:

Code: Select all

rice
lobsters
spaghetti
strawberries
octopi
peaches
turkeys
boys
buys
bays
greys
biys
tooes
vexes
brashes
nexuses
chastes
parks
labels
snakes

Re: 11233 Deli Deli - Runtime Error. please help

Posted: Tue Mar 18, 2014 9:29 am
by uDebug
Shiba wrote:i've got AC with the same alogorithm in C++. But in case of Java there is always RE :( . can anyone plz help me. where is my fault??
Looks like

Code: Select all

Scanner input
is never closed. Perhaps this could contribute to the RE.

Re: 11233 Deli Deli - Runtime Error. please help

Posted: Tue Mar 18, 2014 9:50 pm
by brianfry713
1 ? N ? 100

Re: 11233 - Deli Deli

Posted: Mon Aug 04, 2014 8:23 am
by sampad74
got AC.thanks lighted

Re: 11233 - Deli Deli

Posted: Mon Aug 04, 2014 4:45 pm
by lighted
You are reusing variable l, first for number of irregular words and second for length of each given word. :)

UVA 11233 - Deli Deli WA

Posted: Mon Aug 18, 2014 7:57 pm
by NAbdulla
I can't understand the fault.
Please help...
My Code:

Code: Select all

#include <stdio.h>
#include <string.h>
int isConsonant(char ch)
{
    int f = 1;
    if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'){
        f = 0;
    }
    else{
        f = 1;
    }
    return f;
}
int comp(char s1[], char s2[])
{
    int f = 0, i, l1 = 0, l2 = 0;
    l1 = strlen(s1);
    l2 = strlen(s2);
    if(l1 == l2){
        for(i = 0; i < l1; i++){
            if(s1[i] != s2[i]){
                f = 0;
                break;
            }
            else{
                f = 1;
            }
        }
    }
    return f;
}
int main()
{
    int l, n, i, j, k, len, m, f, p, f1, l1;
    char irr[105][205], tmp1[105], tmp2[105], instr[105];
    scanf("%d %d", &l, &n);
    getchar();
    for(i = 0; i < l; i++){
        gets(irr[i]);
    }
    for(i = 0; i < n; i++){
        gets(instr);
        f1 = 1;
        for(j = 0; j < l; j++){
            len = 0;
            for(p = 0; irr[j][p] != '\0'; p++){
                len++;
            }
            m = 0;
            f = 0;
            f1 = 1;
            for(k = 0; k <= len; k++){
                if(irr[j][k] != ' ' && f == 0){
                    tmp1[m++] = irr[j][k];
                }
                else if(irr[j][k] != '\0' && f == 1){
                    tmp2[m++] = irr[j][k];
                }
                else if(irr[j][k] == ' '){
                    tmp1[m++] = '\0';
                    m = 0;
                    f = 1;
                }
                else if(irr[j][k] == '\0'){
                    tmp2[m] = '\0';
                    f = 0;
                }
            }
            if(comp(tmp1, instr) == 1){
                printf("%s\n", tmp2);
                f1 = 0;
                break;
            }
        }
        if(f1 == 1){
            l1 = strlen(instr);
            if((isConsonant(instr[l1-2]) == 1) && (instr[l1-1] == 'y')){
                for(i = 0; i < l1-1; i++){
                    printf("%c", instr[i]);
                }
                printf("ies\n");
            }
            else if(instr[l1-1] == 'o' || instr[l1-1] == 's' || instr[l1-1] == 'x'){
                printf("%s", instr);
                printf("es\n");
            }
            else if((instr[l1-2] == 'c' || instr[l1-2] == 's') && instr[l1-1] == 'h'){
                printf("%s", instr);
                printf("es\n");
            }
            else{
                printf("%s", instr);
                printf("s\n");
            }
        }
    }
    return 0;
}

Re: UVA 11233 - Deli Deli WA

Posted: Wed Aug 20, 2014 8:29 pm
by lighted
Check input posted by v1n1t in thread below. Your program doesn't output answer for last 6 words.
http://acm.uva.es/board/viewtopic.php?f ... 0d#p370523

Check your output here
http://ideone.com/0axqai

You can read irregular words simpler this way.

Code: Select all

scanf("%d %d", &l, &n);

char singular[30][30], plural[30][30];

for(i = 0; i < l; i++) {

  while (getchar() != '\n');

  scanf(" %s %s", singular[i], plural[i]);
}

Re: 11233 - Deli Deli

Posted: Wed Aug 20, 2014 9:11 pm
by brianfry713
Next time post in an existing thread.