zl程序教程

您现在的位置是:首页 >  其它

当前栏目

WZK的排名

排名
2023-09-27 14:28:26 时间

W Z K 的 排 名 WZK的排名 WZK

题目链接:jzoj 1995

题目大意

我们知道每一位学生的成绩和年纪,我们将他们排序后,求对于每一位学生的前面,有几位学生的年级低于他。
(按分数从高到低排名,分数相同按年级从低到高排)

样例输入

5
300 5
200 6
350 4
400 6
250 5

样例输出

0
0
1
1
3

数据范围

对于100%的数据:1≤n≤200,0≤s≤400,1≤g≤6。

思路

这道题就是一道模拟题。
我们先按题目的要求排序,然后枚举每一个人的每一个在他前面的人,然后判断,统计。
最后每次统计完一个人就输出。

代码

#include<cstdio>
#include<algorithm>
using namespace std;
struct note
{
	int score,grade;
}a[201];
int n;
bool cmp(note x,note y)
{
	return x.score>y.score||(x.score==y.score&&x.grade<y.grade);
}
int main()
{
//	freopen("paiming.in","r",stdin);
//	freopen("paiming.out","w",stdout);
	scanf("%d",&n);//读入
	for (int i=1;i<=n;i++)
	scanf("%d%d",&a[i].score,&a[i].grade);//读入
	sort(a+1,a+n+1,cmp);//按题目要求排序
	printf("%d\n",0);//输出
	for (int i=2;i<=n;i++)
	{
		int ans=0;//初始化
		for (int j=1;j<i;j++)
		if (a[j].grade<a[i].grade) ans++;//统计
		printf("%d\n",ans);//输出
	}
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}