STL_A1054 The Dominant Color (20 分)
Posted 2o2o
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STL_A1054 The Dominant Color (20 分)相关的知识,希望对你有一定的参考价值。
https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768
/* *map的使用 *访问map的键、值 *数字与出现次数的map映射 */ #include<iostream> using namespace std; #include<cstdio> #include<map> int main() int m,n,color; scanf("%d%d",&m,&n); map<int,int> count; //数字与出现次数的map映射 map<int,int>::iterator it; for(int i=0;i<m;i++) for(int j=0;j<n;j++) scanf("%d",&color); if(count.find(color) != count.end()) count[color]++; //若已经存在,则color出现次数加1,否则次数置为1 else count[color]=1; int maxColor=0,maxCount=0; for(it=count.begin();it != count.end();it++) if(it->second > maxCount) //注意是maxCount maxColor=it->first; maxCount=it->second; printf("%d",maxColor); return 0;
以上是关于STL_A1054 The Dominant Color (20 分)的主要内容,如果未能解决你的问题,请参考以下文章