计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科学的评价计算机程序设计人才,为企业选拔人才提供参考标准(网址​​http://www.patest.cn)。​

每次考试会在若干个不同的考点同时举行,每个考点用局域网,产生本考点的成绩。考试结束后,各个考点的成绩将即刻汇总成一张总的排名表。

现在就请你写一个程序自动归并各个考点的成绩并生成总排名表。

输入格式:

输入的第一行给出一个正整数N(≤100),代表考点总数。随后给出N个考点的成绩,格式为:首先一行给出正整数K(≤300),代表该考点的考生总数;随后K行,每行给出1个考生的信息,包括考号(由13位整数字组成)和得分(为[0,100]区间内的整数),中间用空格分隔。

输出格式:

首先在第一行里输出考生总数。随后输出汇总的排名表,每个考生的信息占一行,顺序为:考号、最终排名、考点编号、在该考点的排名。其中考点按输入给出的顺序从1到N编号。考生的输出须按最终排名的非递减顺序输出,获得相同分数的考生应有相同名次,并按考号的递增顺序输出。

输入样例:

2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85

输出样例:

9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4

全部输入后再排序最大 测试点是答案错误不是超时内存超限。。。

我也一时半会儿查不出来

补充:错误很可能是long long 类型导致的,longlong不是精准数据类型,sort可能出错误,改为string 即可通过。

改正后代码

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
struct stu{
string id;
int score;
int kc;
int kcpm;
int zpm;
};
bool cmp0(stu s1,stu s2){
if(s1.kc==s2.kc){
return s1.score>s2.score;
}else return s1.kc<s2.kc;
}
bool cmp1(stu s1,stu s2){
if(s1.score!=s2.score){
return s1.score>s2.score;
}return s1.id<s2.id;
}
vector<stu>st;
int main(){
long long int n;
cin>>n;
for(int i=0;i<n;i++){
int p;
cin>>p;
for(int j=0;j<p;j++){
string a;
int b;
cin>>a>>b;
stu s;
s.id=a;
s.score=b;
s.kc=i+1;
st.push_back(s);
}
}
sort(st.begin(),st.end(),cmp0);
int count=1;
for(int i=0;i<st.size();i++){
if(i>0&&st[i].kc!=st[i-1].kc){
count=1;
}
st[i].kcpm=count++;
if(i>0&&st[i].kc==st[i-1].kc&&st[i].score==st[i-1].score){
st[i].kcpm=st[i-1].kcpm;
}
}
sort(st.begin(),st.end(),cmp1);
cout<<st.size()<<endl;
count=1;
for(int i=0;i<st.size();i++){
st[i].zpm=count++;
if(i>0&&st[i].score==st[i-1].score){
st[i].zpm=st[i-1].zpm;
}
cout<<st[i].id<<" "<<st[i].zpm<<" "<<st[i].kc<<" "<<st[i].kcpm<<endl;
}
return 0;
}


改正前 long long int 数据代码


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
struct stu{
long long int id;
int score;
int kc;
int kcpm;
int zpm;
};
bool cmp0(stu s1,stu s2){
if(s1.kc!=s2.kc){
return s1.kc>s2.kc;
}else {
return s1.score>s2.score;
}
}
bool cmp1(stu s1,stu s2){
if(s1.score!=s2.score){
return s1.score>s2.score;
}return s1.id<s2.id;
}
vector<stu>st;
int main(){
long long int n;
cin>>n;
for(int i=0;i<n;i++){
int p;
cin>>p;
for(int j=0;j<p;j++){
long long a,b;
cin>>a>>b;
stu s;
s.id=a;
s.score=b;
s.kc=i+1;
st.push_back(s);
}
}
sort(st.begin(),st.end(),cmp0);
int count=1;
for(int i=0;i<st.size();i++){
if(i>0&&st[i].kc!=st[i-1].kc){
count=1;
}
st[i].kcpm=count++;
if(i>0&&st[i].kc==st[i-1].kc&&st[i].score==st[i-1].score){
st[i].kcpm=st[i-1].kcpm;
}
}
sort(st.begin(),st.end(),cmp1);
cout<<st.size()<<endl;
count=1;
for(int i=0;i<st.size();i++){
st[i].zpm=count++;
if(i>0&&st[i].score==st[i-1].score){
st[i].zpm=st[i-1].zpm;
}
cout<<st[i].id<<" "<<st[i].zpm<<" "<<st[i].kc<<" "<<st[i].kcpm<<endl;
}
return 0;
}

 超了一个大佬答案过了

xxxxxxxxxx
 
1
#include<bits/stdc++.h>
2
using namespace std;
3
typedef long long ll;
4
const int maxn = 30000+7, INF = 0x7f7f7f7f;
5
int T, n;
6
struct node {
7
    string s;
8
    int sc, id, st, fst;
9
}a[maxn];
10
bool cmp(node a, node b) {
11
    if(a.sc == b.sc) return a.s < b.s;
12
    return a.sc > b.sc;
13
} 
14
int main() {
15
    scanf("%d", &T);
16
    int cnt = 0;
17
    for(int i = 1; i <= T; ++i) {
18
        scanf("%d", &n);
19
        string s; int x;
20
        for(int j = 0; j < n; ++j) {
21
            cin >> s >> x;
22
            a[cnt+j].s = s; a[cnt+j].sc = x; a[cnt+j].id = i;
23
        }
24
        sort(a+cnt, a+cnt+n, cmp);
25
        a[cnt].st = 1;
26
        for(int j = 1; j < n; ++j) {
27
            if(a[cnt+j].sc == a[cnt+j-1].sc) a[cnt+j].st = a[cnt+j-1].st;
28
            else a[cnt+j].st = j+1;
29
        }
30
        cnt += n;
31
    }
32
    sort(a, a+cnt, cmp);
33
    cout << cnt << endl;
34
    a[0].fst = 1;
35
    cout << a[0].s << " " << a[0].fst << " " << a[0].id << " " << a[0].st << endl;
36
    for(int i = 1; i < cnt; ++i) {
37
        if(a[i].sc == a[i-1].sc) a[i].fst = a[i-1].fst;
38
        else a[i].fst = i+1;
39
        cout << a[i].s << " " << a[i].fst << " " << a[i].id << " " << a[i].st << endl;
40
    }
41
    return 0;
42
}
43
/*
44
2
45
5
46
1234567890001 95
47
1234567890005 100
48
1234567890003 95
49
1234567890002 77
50
1234567890004 85
51
4
52
1234567890013 65
53
1234567890011 25
54
1234567890014 100
55
1234567890012 85
56
*/