PAT1054

来源:互联网 发布:php object to array 编辑:程序博客网 时间:2024/05/22 14:41

题目链接PAT1054(A)
本题需要注意的是应当知道采用c++的输入方式会超时,故应当采用c的处理方式,代码如下:

#include <iostream>#include <map>using namespace std;map<int, int> mymap;map<int, int>::iterator it;int main(){    int m, n,s,max=0,flag=-1;    cin >> m >> n;    for (int i = 0; i < n; i++){        for (int j = 0; j < m; j++){            scanf("%d", &s);            mymap[s]++;        }    }    for (it = mymap.begin(); it != mymap.end(); it++){        if (it->second>max){            max = it->second;            flag = it->first;        }    }    printf("%d", flag);    system("pause");    return 0;}
0 0
原创粉丝点击