码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 1585. Penguins (字符串)

时间:2015-03-07 17:16:10      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

1585. Penguins

Time limit: 1.0 second
Memory limit: 64 MB
Programmer Denis has been dreaming of visiting Antarctica since his childhood. However, there are no regular flights to Antarctica from his city. That is why Denis has been studying the continent for the whole summer using a local cinema. Now he knows that there are several kinds of penguins:
  • Emperor Penguins, which are fond of singing;
  • Little Penguins, which enjoy dancing;
  • Macaroni Penguins, which like to go surfing.
Unfortunately, it was not said in the cartoons which kind of penguins was largest in number. Petya decided to clarify this. He watched the cartoons once more and every time he saw a penguin he jotted down its kind in his notebook. Then he gave his notebook to you and asked you to determine the most numerous kind of penguins.

Input

The first line contains the number n of entries in the notebook (1 ≤ n ≤ 1000). In each of the next n lines, there is the name of a kind of penguins, which is one of the following: “Emperor Penguin,” “Little Penguin,” and “Macaroni Penguin.”

Output

Output the most numerous kind of penguins. It is guaranteed that there is only one such kind.

Sample

input output
7
Emperor Penguin
Macaroni Penguin
Little Penguin
Emperor Penguin
Macaroni Penguin
Macaroni Penguin
Little Penguin
Macaroni Penguin




题意:统计三个字符串那个出现得最多。

解析:由于每个字符串中间有空格,所以可以用gets直接读取整个字符串,也可以用scanf或cin把它分成两个部分来读。



AC代码:

#include <cstdio>
#include <iostream>
using namespace std;

int main(){
    #ifdef sxk
        freopen("in.txt", "r", stdin);
    #endif //sxk

    string s, ss;
    int n, e, m, l;
    while(cin>>n){
        e = m = l = 0;
        for(int i=0; i<n; i++){
            cin>>s>>ss;
            if(s[0] == 'E') e ++;
            else if(s[0] == 'M') m ++;
            else l ++;
        }
        if(e > m && e > l) puts("Emperor Penguin");
        else if(m > e && m > l) puts("Macaroni Penguin");
        else puts("Little Penguin");
    }
    return 0;
}



URAL 1585. Penguins (字符串)

标签:

原文地址:http://blog.csdn.net/u013446688/article/details/44117127

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!