Ural1585(细节)

来源:互联网 发布:虚拟定位软件 编辑:程序博客网 时间:2024/06/05 20:24

题目链接:点击打开链接


解题思路:

很简单,但细节很坑。用getline之前要来个getchar把输入n后的回车吃掉,经过被加速器坑过这么多次后,我就决定以后还是不用加速器了。


完整代码:

#include <algorithm>#include <iostream>#include <cstring>#include <climits>#include <cstdio>#include <string>#include <cmath>#include <map>#include <queue>using namespace std;typedef long long LL;const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;const double PI = acos(-1.0); //M_PI;string s;int max(int a , int b , int c){    int k = a > b ? a : b;    return k > c ? k : c;}int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    int n;    cin >> n;    int a = 0 , b = 0 , c = 0;    getchar();    for(int i = 0 ; i < n ; i ++)    {        getline(cin , s);        if(s == "Emperor Penguin")            a ++;        else if(s == "Little Penguin")            b ++;        else if(s == "Macaroni Penguin")            c ++;    }    int res = max(a , b , c);    if(res == a)        cout << "Emperor Penguin" << endl;    else if(res == b)        cout << "Little Penguin" << endl;    else if(res == c)        cout << "Macaroni Penguin" << endl;}

更多精彩请访问:点击打开链接

0 0
原创粉丝点击