zoukankan      html  css  js  c++  java
  • A1141 PAT Ranking of Institutions [stl]

    在这里插入图片描述
    注意最后一个测试点用unordered_map

    #include<iostream>
    #include<vector>
    #include<map>
    #include<string>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<set>
    #include<queue>
    #include<unordered_map>
    using namespace std;
    const int maxn = 100001;
    struct node
    {
    	string name;
    	int endscore;
    	double score;
    	int count;
    };
    vector<node>v;
    unordered_map<string, int>m;
    unordered_map<string, int>Rank;
    bool cmp(node a, node b)
    {
    	if (a.endscore != b.endscore)
    		return a.endscore > b.endscore;
    	else if (a.count != b.count)
    		return a.count < b.count;
    	else
    		return a.name < b.name;
    }
    string dazhuanxiao(string s)
    {
    	for (int i = 0; i < s.size(); i++)
    	{
    		if (s[i] <= 'Z' && s[i]>='A')
    		{
    			s[i] = s[i] + 32;
    		}
    	}
    	return s;
    }
    int main()
    {
    	int n; cin >> n; int cnt = 1;
    	string id, name; double score;
    	for (int i = 0; i < n; i++)
    	{
    		cin >> id >> score >> name;
    		name = dazhuanxiao(name);
    		if (m[name] != 0)
    		{
    			if (id[0] == 'T')
    			{
    				v[m[name] - 1].score += score*1.5;
    				v[m[name] - 1].count++;
    			}
    			else if (id[0] == 'A')
    			{
    				v[m[name] - 1].score += score;
    				v[m[name] - 1].count++;
    			}
    			else
    			{
    				v[m[name] - 1].score += score/(1.5);
    				v[m[name] - 1].count++;
    			}
    		}
    		else {
    			if (id[0] == 'T')
    			{
    				v.push_back(node{ name, 0,score*1.5,1});
    			}
    			else if (id[0] == 'A')
    			{
    				v.push_back(node{ name, 0,score,1});
    			}
    			else
    			{
    				v.push_back(node{ name, 0,score/(1.5),1});
    			}
    			m[name] = cnt++;
    		}
    	}
    	for (int i = 0; i < v.size(); i++)
    	{
    		v[i].endscore = int(v[i].score);
    	}
    	sort(v.begin(), v.end(), cmp);
    	Rank[v[0].name] = 1;
    	for (int i = 1; i < v.size(); i++)
    	{
    		if (v[i].endscore == v[i - 1].endscore)
    			Rank[v[i].name] = Rank[v[i - 1].name];
    		else
    			Rank[v[i].name] = i + 1;
    	}
    	cout << v.size() << endl;
    	for (int i = 0; i < v.size(); i++)
    	{
    	
    		cout << Rank[v[i].name] << " " << v[i].name << " " << v[i].endscore << " " << v[i].count << endl;
    	}
    }
    
  • 相关阅读:
    内存
    TCP/IP
    安装
    linux常用命令
    linux文本处理三剑客之 grep
    tail命令:显示文件结尾的内容
    less命令:查看文件内容
    head命令:显示文件开头内容
    改进Zhang Suen细化算法的C#实现
    【转】在VS2010上使用C#调用非托管C++生成的DLL文件(图文讲解)
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13811957.html
Copyright © 2011-2022 走看看