/因为这道题之前做过一次,看了别人的算法思想用local跟galobal排序并插入,所以一写就是照着这个思想来的,记得第一次做的时候用sort分段排序,麻烦要记录起始位置,好像最后还没A,这次用别人的思想在比较函数出出了点问题,没有意识到别人直接用的string,而我用的字符串数组,比较时要加strcmp;小白啊,大神通篇都是库函数。。。。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct node
{
char id[15];
int score;
int location;
int lrank;
int rank;
};
bool cmp(node a,node b)
{
if(a.score!=b.score)
return a.score>b.score;
else return strcmp(a.id,b.id)<0;
}
vector<node>local,galobal;
int main()
{
freopen("input.txt","r",stdin);
int i,j,n,k;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
{
scanf("%d",&k);
for(j=0;j<k;j++)
{
node s;
scanf("%s %d",s.id,&s.score);
s.location=i;
local.push_back(s);
}
sort(local.begin(),local.end(),cmp);
for(j=0;j<local.size();j++)
{
if(j!=0&&local[j].score==local[j-1].score)local[j].lrank=local[j-1].lrank;
else local[j].lrank=j+1;
}
galobal.insert(galobal.end(),local.begin(),local.end());
local.clear();
}
sort(galobal.begin(),galobal.end(),cmp);
for(i=0;i<galobal.size();i++)
{
if(i!=0&&galobal[i].score==galobal[i-1].score)galobal[i].rank=galobal[i-1].rank;
else galobal[i].rank=i+1;
}
printf("%d\n",galobal.size());
for(i=0;i<galobal.size();i++)
{
printf("%s %d %d %d\n",galobal[i].id,galobal[i].rank,galobal[i].location,galobal[i].lrank);
}

}
return 0;
}

PAT1025. PAT Ranking的更多相关文章

  1. pat1025. PAT Ranking (25)

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  2. PAT Ranking (排名)

    PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  3. 1025 PAT Ranking[排序][一般]

    1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...

  4. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  5. 1141 PAT Ranking of Institutions[难]

    1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...

  6. A1025 PAT Ranking (25)(25 分)

    A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...

  7. PAT_A1141#PAT Ranking of Institutions

    Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...

  8. PAT_A1025#PAT Ranking

    Source: PAT A1025 PAT Ranking Description: Programming Ability Test (PAT) is organized by the Colleg ...

  9. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

随机推荐

  1. OAF_VO系列1 - Accelerator Keys

    OAF_EO系列6 - Delete详解和实现(案例) (2014-06-16 08:37)

  2. NeHe OpenGL教程 第九课:移动图像

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  3. DirFile

    using System; using System.Text; using System.IO; namespace MyListen { /// <summary> /// 文件操作夹 ...

  4. CSS背景属性Background详解

    [转] 本文详解了CSS的背景属性Background,包括CSS3中新增的背景属性.如果你是个CSS初学者,还可以查看之前介绍的CSS浮动属性和CSS透明属性详解. CSS2 中有5个主要的背景(b ...

  5. 转--Android如何在java代码中设置margin

    ========  3 在Java代码里设置button的margin(外边距)? 1.获取按钮的LayoutParams LinearLayout.LayoutParams layoutParams ...

  6. Java中的String与常量池

    string是java中的字符串.String类是不可变的,对String类的任何改变,都是返回一个新的String类对象.下面介绍java中的String与常量池. 1. 首先String不属于8种 ...

  7. python第一个hello world注意问题!!

    如果你第一次写python代码,想写一个通常的hello world ,那么你需要注意这个hello world的写法,这和python的版本有直接关系!!! Python 3.x: print('h ...

  8. Bug 是改不完滴

  9. c#生成缩略图

    publicstaticvoidGenThumbnail(Image imageFrom,stringpathImageTo,intwidth,intheight)         {         ...

  10. jsLint配置参数解释

    转自: http://www.cnblogs.com/elementstorm/archive/2013/04/10/3012679.htmlanon :true //匿名函数声明中function关 ...