zoukankan      html  css  js  c++  java
  • 【编程基本功练习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;
    };
    

      

  • 相关阅读:
    Tensor总结
    Tensorflow池化
    conda操作
    KS值计算
    supervisor实践
    npm/yarn实践
    nni 环境搭建
    阿里云个人邮箱配置
    Jinja2宏使用
    利用VS code 远程调试 docker 中的 dotnet 应用
  • 原文地址:https://www.cnblogs.com/foreveryl/p/2554075.html
Copyright © 2011-2022 走看看