• 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;
    }
    
    
  • 相关阅读:
    python Database Poll for SQL SERVER
    SQLAlchemy表操作和增删改查
    flask动态url规则
    flask配置管理
    一个Flask运行分析
    Function Set in OPEN CASCADE
    Happy New Year 2016
    Apply Newton Method to Find Extrema in OPEN CASCADE
    OPEN CASCADE Multiple Variable Function
    OPEN CASCADE Gauss Least Square
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812079.html
Copyright © 2020-2023  润新知