PAT Basic Level 1085 PAT单位排行 (25 分)

题目链接:

https://pintia.cn/problem-sets/994805260223102976/problems/994805260353126400

22分代码(测试点5没通过,网上说是:输出分数是整数,我的也时输出整数,但是没通过,还望大佬订正):

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

const int maxn=100010;
struct SCHOOL{
    char number[6];
    int score;
    char school[6];
}sch[maxn];
/*
bool cmp(map::iterator a,map::iterator b){
    return a->second > b->second;
}
*/
//学校名称,总分存储
map m;
map amount;//存储学校人数

int a[maxn];//用于输出排名
int main(){
    int N;
    scanf("%d",&N);
    for(int i=0;i= 'A') && (sch[i].school[j] <= 'Z'))
                sch[i].school[j]+='a'-'A';
        amount[sch[i].school]++;
    }
    for(int i=0;i >_cnt;
    int num=1;
    for(map::iterator itr = m.begin();itr!=m.end();itr++)
    {
        _cnt.insert(pair(itr->second,itr->first));
    }

    for(multimap >::iterator it=_cnt.begin();it!=_cnt.end();it++){
        int tmp=it->first;
        a[num++]=tmp;
    }
    int rank_=1;
    int i=1;
    cout<<_cnt.size()< >::iterator it=_cnt.begin();it!=_cnt.end();it++){
        int score=it->first;
        if(i==1){
            printf("1 ");
        }
        else if(a[i]==a[i-1]){
            printf("%d ",rank_);
        }
        else if(a[i]!=a[i-1]){
            rank_=i;
            printf("%d ",i);
        }
        i++;
//        cout<first<<" "<second<second<<" "<second]<

 

参考的满分代码:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

const int maxn = 100010;
struct SCHool {
	string name;//插入存在一一对应的关系
	int toSco;
	int peo;
}sch[maxn];

bool cmp(struct SCHool a, struct SCHool b) {
	if (a.toSco != b.toSco)
		return a.toSco > b.toSco;
	else if (a.peo != b.peo)
		return a.peo < b.peo;
	else
		return a.name < b.name;
}
unordered_map sum;
unordered_map cnt;

int main() {
	int n;
	scanf("%d", &n);
	string tmp_name, tmp_sch;
	double tmp_scr;
	for (int i = 0; i < n; i++) {
		cin >> tmp_name;
		scanf("%lf", &tmp_scr);
		cin >> tmp_sch;
		for (int j = 0; j < tmp_sch.size(); j++) {
			tmp_sch[j] = tolower(tmp_sch[j]);
		}
		if (tmp_name[0] == 'B')
			tmp_scr /= 1.5;
		else if (tmp_name[0] == 'T')
			tmp_scr *= 1.5;
		sum[tmp_sch] += tmp_scr;
		cnt[tmp_sch]++;
	}
	vector ans;

	for (auto it = cnt.begin(); it != cnt.end(); it++) {
		ans.push_back(SCHool{ it->first,(int)sum[it->first],cnt[it->first] });
	}
	sort(ans.begin(), ans.end(), cmp);
	int len = ans.size();
	int rank = 1;

  printf("%d\n",len);
	printf("1 ");
	cout << ans[0].name;
	printf(" %d %d\n", ans[0].toSco, ans[0].peo);
	for (int i = 1; i < len; i++) {
		if (ans[i].toSco != ans[i-1].toSco) {
			rank = i + 1;
			printf("%d ", rank);
		}
		else {
			printf("%d ", rank);
		}
		cout << ans[i].name;
		printf(" %d %d\n", ans[i].toSco, ans[i].peo);
	}

	return 0;
}

 

你可能感兴趣的:(PAT,PAT,Basic,Level)