T3 成绩单 题解

这个题本来不归我讲,但我A完之后觉得太坑了,还是讲一下吧。

首先这个题有个重要的地方:(字典顺序,学号全为小写字母,从小到大排列)

字典序和字典顺序是不一样的!!!

我以为是字典序……,wa了,字典顺序就是忽略长度的字典序。

这个题值得格外写出来的只有这个地方,哦,还有一个0分,0分不计算在内,这个要注意。别的东西直接写在代码注释里吧。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
long long zx=0,n,mf;
string mfsz[10005];
struct hehe
{
	string s;
	long long fs;
}sz[130005];
long long a[50];
int px(struct hehe a1,struct hehe a2)//真坑
{
	return a1.s<a2.s;
}
int main()
{
	freopen("result.in","r",stdin);
	freopen("result.out","w",stdout);
	scanf("%lld",&n);
	for(int i=0;i<n;i++)
	{
		cin>>sz[i].s>>sz[i].fs;
	}
	sort(sz,sz+n,px);
	for(int i=0;i<n;i++)
	{
		if(sz[i].fs==150)//如果出现了满分的大佬,当然要保存一下
		{
			mfsz[mf]=sz[i].s;
			mf++;
		}else if(sz[i].fs!=0)//他不等于0分,统计一下分数。
		{
			a[sz[i].fs/10]++;
		}
	}
	cout<<"1~9 10~19 20~29 30~39 40~49 50~59 60~69 70~79 80~89 90~99 100~109 110~119 120~129 130~139 140~149"<<endl;
	for(int i=0;i<15;i++)
	{
		if(i==14)//最后一个是回车,不带空格的那种。
		{
			cout<<a[i]<<endl;
		}else
		{
			cout<<a[i]<<" ";
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<sz[i].s<<" "<<sz[i].fs<<endl;
	}
	if(mf==0)//他是0,特判一下
	{
		cout<<0<<endl;
		cout<<"No"<<endl;
		return 0;
	}
	cout<<mf<<endl;
	for(int i=0;i<mf;i++)
	{
		cout<<mfsz[i]<<endl;
	}
	return 0; 	
}

嗯,美好的结束了,除了那个坑都挺简单的。希望帮到了不会做的同学。

原文地址:https://www.cnblogs.com/lichangjian/p/12874863.html