【编程基本功练习0】zoj 3486

不是什么难题, 就为了写点c++代码, 别给忘了。 

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4283

//AC

#include <iostream>

#include <vector>

#include <map>

#include <string>

#include <cstdio>

#include <cstdlib>

#include <algorithm>



using namespace std;



struct Node {

	int num;

	int count;

	Node(int a, int b = 1) : num(a), count(b) {};

	void inc_count() { count += 1; }

	friend bool operator<(const Node& left, const Node& right) {

		if(left.count == right.count) {

			return left.num > right.num;

		} else {

			return left.count > right.count;

		}

	}

};



class Base {

public:

	Base() {};

private:

	vector<Node> node_list;

	map<int, int> count_map;



public:

	void push_num(int n) {

		count_map[n] += 1;

	}

	int run() {

		map<int, int>::iterator iter;

		for(iter = count_map.begin(); iter != count_map.end(); ++iter) {

			node_list.push_back(Node(iter->first, iter->second));

		};

		sort(node_list.begin(), node_list.end());

		return node_list[0].num;

	};

};



int main() {

	freopen("test_input.lst", "r", stdin);

	int N;

	cin >> N;

	while(N--) {

		int line_num;

		Base T;

		cin >> line_num;

		for(int i = 0; i < line_num; i++) {

			int n;

			cin >> n;

			T.push_num(n);

		};

		cout << T.run() << endl;

	};

	return 0;

};

  

你可能感兴趣的:(ZOJ)