TEMA

Wrong answer (85%)

Alex57 preguntado 4 years ago

Pessoal, se alguém puder ajudar... não entendi porque meu código não está retornando corretamente.


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

int calc(int mult, char fruta[]) {
    int tot = 0;
    if(strcmp(fruta, "suco de laranja")) {
        tot += mult * 120;
    }else if((strcmp(fruta, "morango fresco")) || (strcmp(fruta, "mamao"))) {
        tot += mult * 85;
    }else if(strcmp(fruta, "goiaba vermelha")) {
        tot += mult * 70;
    }else if(strcmp(fruta, "manga")) {
        tot += mult * 56;
    }else if(strcmp(fruta, "laranja")) {
        tot += mult * 50;
    }else if(strcmp(fruta, "brocolis")) {
        tot += mult * 34;
    }
    return tot;
}

int main() {
    int n, mult, i;
    long long int tot;
    char fruta[17];
    while(scanf("%d", &n) != 0) {
        tot = 0;
        mult = 0;
        for(i = 0; i < n; i++) {
            scanf("%s", fruta);
            tot = calc(mult, fruta);
            n--;
        }
        if(tot < 110) {
            printf("Mais %lli mg\n", (110 - tot));
        }else if(tot > 130) {
            printf("Menos %lli mg\n", (tot - 130));
        }else if ((tot >= 110) && (tot <= 130)){
            printf("%lli mg\n", tot);
        }
   }
}

Recuerda no enviar soluciones. Tu mensaje puede ser revisado por nuestros moderadores.

  • feodorv respondido 4 years ago

            for(i = 0; i < n; i++) {
                scanf("%s", fruta);

    Oh. The format of the next n lines is

    <count> <string_with_spaces>

    And string_with_spaces can't read with

    scanf( "%s", fruta);

    Also:

        while(scanf("%d", &n) != 0) {

    Here n can be zero, and this value is the marker for finishing the cycle.