A1054 The Dominant Color (20分)

一、技术总结

  1. 这个题目也是使用map STL来解决问题。
  2. 直接使用map<int, int>,同时题目规定是严格的Dominate Color,只要有超过一半的数,就可以输出,然后return 0;

二、参考代码

#include<iostream>
#include<map> 
using namespace std;
int main(){
	int m, n;
	scanf("%d %d", &m, &n);
	map<int, int> count;
	int half;
	half = m * n / 2;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			int temp;
			scanf("%d", &temp);
			count[temp]++;
			if(count[temp] > half){
				printf("%d", temp);
				return 0;
			}
		}
	}
	return 0;
}
posted @ 2020-01-31 15:22  睿晞  阅读(96)  评论(0编辑  收藏  举报