zoukankan      html  css  js  c++  java
  • A1153 Decode Registration Card of PAT

    在这里插入图片描述

    #include<iostream>
    #include<vector>
    #include<map>
    #include<string>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<set>
    #include<queue>
    #include<unordered_map>
    #include<cmath>
    using namespace std;
    const int maxn = 10010;
    struct node
    {
    	string id;
    	int score;
    };
    
    bool cmp(node a, node b)
    {
    	return a.score != b.score ? a.score > b.score : a.id < b.id;
    }
    
    
    int main()
    {
    	int n, m,q;
    	cin >> n >> m;
    	vector<node>v(n);
    	string s; 
    	for (int i = 0; i < n; i++)
    	{
    		cin >> v[i].id >> v[i].score;		
    	}
    	for (int i = 1; i <= m; i++)
    	{
    		cin >> q >> s;
    		int people = 0, allscore = 0;
    		printf("Case %d: %d %s
    ", i, q, s.c_str());
    		vector<node>ans;
    		if (q == 1)
    		{
    			for (int j = 0; j < v.size(); j++)
    			{
    				if (v[j].id[0] == s[0]) 
    					ans.push_back(v[j]);
    			}
    		}
    		else if (q == 2)
    		{
    			for (int j = 0; j < v.size(); j++)
    			{
    				if (v[j].id.substr(1, 3) == s)
    				{
    					people++;
    					allscore += v[j].score;
    				}
    			}
    			if (people != 0) printf("%d %d
    ", people, allscore);
    		}
    		else if (q == 3)
    		{
    			unordered_map<string, int> m;
    			for (int j = 0; j < n; j++)
    				if (v[j].id.substr(4, 6) == s) m[v[j].id.substr(1, 3)]++;
    			for (auto it = m.begin(); it != m.end(); it++)
    				ans.push_back({ it->first,it->second });
    		}
    		sort(ans.begin(), ans.end(), cmp);
    		for (int j = 0; j < ans.size(); j++)
    			printf("%s %d
    ", ans[j].id.c_str(), ans[j].score);
    		if (((q == 1 || q == 3) && ans.size() == 0) || (q == 2 && people == 0)) printf("NA
    ");
    	}
    
    }
    
  • 相关阅读:
    Redis Cluter
    数据库设计范式
    kvm虚拟化
    架构前端
    集群架构
    初识shell编程
    网络知识
    Linux三剑客
    Linux磁盘管理
    高性能异步爬虫
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13811946.html
Copyright © 2011-2022 走看看