1025.PAT Ranking (25)

1025.PAT Ranking (25)

pat-al-1025

2017-02-21

  • 每一考场排一次序;所有考生排一次序
/**
 * pat-al-1025
 * 2017-02-21
 * Cpp version
 * Author: fengLian_s
 */
#include<stdio.h>
#include<algorithm>
#define MAX 30010
using namespace std;
struct TESTEE
{
  long long id;
  int score;
  int location;
  int rank[2];//0: final rank;1: local rank
}testee[MAX];
bool cmp(TESTEE a, TESTEE b)
{
  if(a.score != b.score)
    return a.score > b.score;
  else
    return a.id < b.id;
}
int main()
{
  freopen("in.txt", "r", stdin);
  int n, k;
  scanf("%d", &n);
  int cnt = 0, start, end;
  for(int i = 1;i <= n;i++)
  {
    scanf("%d", &k);
    start = cnt;
    for(int j = 0;j < k;j++)
    {
      scanf("%lld%d", &testee[cnt].id, &testee[cnt].score);
      testee[cnt].location = i;
      cnt++;
    }
    end = cnt;
    sort(testee+start, testee+end, cmp);
    for(int j = start;j < end;j++)
    {
      if(j != start && testee[j].score == testee[j-1].score)
      {
        testee[j].rank[1] = testee[j-1].rank[1];
      }
      else
      {
        testee[j].rank[1] = j - start + 1;
        //printf("j = %d, rank = %d\n", j, testee[j].rank[1]);
      }
    }
  }
  sort(testee, testee+cnt, cmp);
  for(int i = 0;i < cnt;i++)
  {
    if(i != 0 && testee[i].score == testee[i-1].score)
      testee[i].rank[0] = testee[i-1].rank[0];
    else
      testee[i].rank[0] = i + 1;
  }
  printf("%d\n", cnt);
  for(int i = 0;i < cnt;i++)
  {
    printf("%013lld %d %d %d\n", testee[i].id, testee[i].rank[0], testee[i].location, testee[i].rank[1]);
  }
  return 0;
}

-FIN-

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值