PAT(A)1054 The Dominant Color (20分)

在这里插入图片描述

Sample Input

5 3
0 0 255 16777215 24
24 24 0 0 24
24 0 24 24 24

Sample Output

24

思路:
找到占一半以上的就是答案,直接输入计数即可。
A的快乐!!!
代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;

typedef long long ll;
#define error 100001
#define endl '\n'

map<string, int>mp;
string a;
string ans;

int main()
{
    int n, m;

    cin >> n >> m;
    for (int i = 0; i < n * m; ++i)
    {
        cin >> a;
        mp[a]++;
        if (mp[a] >= n * m / 2)
            ans = a;
    }
    cout << ans << endl;

    // getchar(); getchar();
    return 0;
}

发布了161 篇原创文章 · 获赞 7 · 访问量 7101

猜你喜欢

转载自blog.csdn.net/weixin_43778744/article/details/103976178