ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1585. Penguins

Please help! Wrong answer 5!
Posted by Grigorenko Vlad 19 May 2012 11:22
#include<stdio.h>

int main(void){
    int n,i,k1,k2,k3;
    char s[30];
    scanf("%d",&n);
    k1=k2=k3=0;
    for(i=1;i<=n;i++){
        scanf("%s",s);
        if(s[0]=='E')
            k1++;
        else
            if(s[0]=='L')
                k2++;
        else
            k3++;
    }
    if(k1>k2 && k1>k3)
        printf("Emperor Penguin");
    else
        if(k2>k1 && k2>k3)
            printf("Little Penguin");
    else
        if(k3>k1 && k3>k2)
            printf("Macaroni Penguin");
return 0;
}

Re: Please help! Wrong answer 5!
Posted by Smilodon_am [Obninsk INPE] 21 May 2012 11:36
Function "scanf" reads array of char and stops when meet any white-space symbol (space, carriage return, tab). So when input contain "Emperor Penguin" first time you get "Emperor", second time you get "Penguin". Second part of string gives you k3++.

Edited by author 21.05.2012 11:45
Re: Please help! Wrong answer 5!
Posted by Grigorenko Vlad 26 May 2012 01:33
Thank you!