• A1075 PAT Judge [排序]


    在这里插入图片描述

    思路:

    1. 这题意思是连续的学号,我一开始以为是分开的学号,然后搞得数组很大,超时了一个测试点,后面都改了一遍。还是挺有难度的。
    2. 逻辑要清晰点,条件要写齐。比如这两个条件我就有遗忘,理所当然了。先拿输入的成绩比较,最后再换这样分开好一些。蓝瘦香菇鸭~

    在这里插入图片描述

    ——————————————————————————————————————————————————

    #include<iostream>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    struct student
    {
    	int id;
    	int score[6];
    	int fullcount = 0;
    	bool flag = false;
    	int allscore = 0;
    	int rank;
    }stu[100001];
    bool cmp(student a, student b)
    {
    	if (a.allscore != b.allscore)
    		return a.allscore > b.allscore;
    	else if (a.fullcount != b.fullcount)
    		return a.fullcount > b.fullcount;
    	else return a.id < b.id;
    }
    int full[5];
    int main()
    {
    	int n, k, m;
    	cin >> n >> k >> m;
    	for (int i = 1; i <= n; i++)
    	{
    		stu[i].id = i;
    		memset(stu[i].score, -1, sizeof(stu[i].score));
    	}
    	for (int i = 1; i <= k; i++)
    	{
    		cin >> full[i];
    	}
    	int id = 0, testid = 0, score = -1;
    	for (int i = 0; i < m; i++)
    	{
    		cin >> id >> testid >> score;
    		if (score >= 0)
    		{
    			stu[id].flag = 1;
    		}
    		if (score == -1&&stu[id].score[testid]==-1)           
    		{
    			stu[id].score[testid] = 0;
    		}
    		if (score == full[testid]&&stu[id].score[testid]<full[testid])
    		{
    			stu[id].fullcount++;
    		}
    		if (score > stu[id].score[testid])
    		{
    			stu[id].score[testid] = score;
    		}
    	}
    	for (int i = 1; i <= n; i++)
    	{
    		for (int j = 1; j <= k; j++)
    		{
    			if (stu[i].score[j] != -1) {
    				stu[i].allscore += stu[i].score[j];
    			}
    		}
    	}
    	sort(stu+1, stu + n+1, cmp);
    	stu[1].rank = 1;
    	for (int i = 2; i <= n&&stu[i].flag; i++)
    	{
    		if (stu[i].allscore == stu[i - 1].allscore)
    		{
    			stu[i].rank = stu[i - 1].rank;
    		}
    		else
    		{
    			stu[i].rank = i;
    		}
    	}
    	for(int i = 1; i <=n; i++)
    	{
    		if (stu[i].flag)
    		{
    			cout << stu[i].rank;
    			printf(" %05d %d",stu[i].id,stu[i].allscore);
    			for (int j = 1; j <= k; j++)
    			{
    				if (stu[i].score[j] >= 0)
    					cout << " " << stu[i].score[j];
    				else
    					cout << " " << "-";
    			}
    			cout << endl;
    		}
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    POJ 2411 状态压缩递,覆盖方案数
    POJ 2774 最长公共子串
    POJ 1743 不可重叠的最长重复子串
    POJ 3294 出现在至少K个字符串中的子串
    POJ 3261 出现至少K次的可重叠最长子串
    POJ 1741/1987 树的点分治
    HDU1556 Color the ball
    解决linux系统时间不对的问题
    CentOS 6.9使用Setup配置网络(解决dhcp模式插入网线不自动获取IP的问题)
    Linux网络配置(setup)
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812079.html
Copyright © 2020-2023  润新知