zoukankan      html  css  js  c++  java
  • 1075 PAT Judge (25)

    排序题

    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <map>
    
    using namespace std;
    
    const int N = 100005;
    
    int score[10];
    
    struct Node
    {
    	int id;
    	int problem;
    	int get;
    }person[N];
    
    
    struct ANS
    {
    	int rank;
    	int id;
    	int total;
    	int get[6];
    	bool flag;
    	int perfect;
    }ans[10005];
    
    int cmp1(const ANS &a, const ANS &b)
    {
    	if (a.total != b.total)
    		return a.total > b.total;
    	if (a.perfect != b.perfect)
    		return a.perfect > b.perfect;
    	else return a.id < b.id;
    }
    
    void get_total(int n, int m, int k)
    {
    	int i = 0, j = 0;
    
    	for (i = 1; i <= n; i++)
    	{
    		for (j = 1; j <= m; j++)
    			ans[i].get[j] = -2;
    		ans[i].flag = 0;
    		ans[i].perfect = 0;
    	}
    
    	for (i = 0; i < k; i++)
    	{
    		int idx = person[i].id;
    		int pro = person[i].problem;
    		int soc = person[i].get;
    
    		if (soc == score[pro] && ans[idx].get[pro] != soc)
    			ans[idx].perfect++;
    		if (soc > ans[idx].get[pro])
    			ans[idx].get[pro] = soc;
    	}
    
    	for (i = 1; i <= n; i++)
    	{
    		int sum = 0;
    		for (j = 1; j <= m; j++)
    		{
    			if (ans[i].get[j] >= 0)
    			{
    				ans[i].flag = 1;
    				sum += ans[i].get[j];
    			}
    		}
    		ans[i].total = sum;
    		ans[i].id = i;
    	}
    }
    
    void get_rank(int n)
    {
    	int rank = 1;
    	int i = 0;
    	
    	ans[1].rank = 1;
    	for (i = 2; i <= n; i++)
    	{
    		if (ans[i].total == ans[i - 1].total)
    			ans[i].rank = ans[i - 1].rank;
    		else ans[i].rank = i;
    	}
    }
    
    void print_info(int n, int m)
    {
    	for (int i = 1; i <= n; i++)
    	{
    		if (ans[i].flag == 0) continue;
    
    		printf("%d %05d %d", ans[i].rank, ans[i].id, ans[i].total);
    
    		for (int j = 1; j <= m; j++)
    		{
    			if (ans[i].get[j] == -2)
    				printf(" -");
    			else if (ans[i].get[j] == -1)
    				printf(" 0");
    			else
    				printf(" %d", ans[i].get[j]);
    		}
    
    		printf("
    ");
    	}
    }
    
    
    
    int main()
    {
    	int n, m, k;
    	int i;
    	while (scanf("%d%d%d", &n, &m, &k) != EOF)
    	{
    		for (i = 1; i <= m; i++)
    			scanf("%d", &score[i]);
    
    		for (i = 0; i < k; i++)
    			scanf("%d%d%d", &person[i].id, &person[i].problem, &person[i].get);
    
    		//sort(person, person, cmp);
    
    		get_total(n, m, k);
    
    		sort(ans + 1, ans + n + 1, cmp1);
    
    		get_rank(n);
    
    		print_info(n, m);
    	}
    	return 0;
    }
    
    
    
    
    
    
    
    	
    
    
    	
    

      

  • 相关阅读:
    谈谈jQuery之绑定事件
    手机移动端WEB资源整合
    2016移动端web5分钟速成(适合新手)
    日常整理的一些网址
    web服务器页面错误代码集
    jQuery事件绑定的最佳实践
    前端体系
    js刷新页面的几种方法
    JAVA的静态变量、静态方法、静态类
    在Hadoop集群中添加机器和删除机器
  • 原文地址:https://www.cnblogs.com/echobfy/p/3576805.html
Copyright © 2011-2022 走看看