PAT1025. PAT Ranking
/因为这道题之前做过一次,看了别人的算法思想用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的更多相关文章
- pat1025. PAT Ranking (25)
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- PAT Ranking (排名)
PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...
- 1025 PAT Ranking[排序][一般]
1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 1141 PAT Ranking of Institutions[难]
1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...
- A1025 PAT Ranking (25)(25 分)
A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...
- PAT_A1141#PAT Ranking of Institutions
Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...
- PAT_A1025#PAT Ranking
Source: PAT A1025 PAT Ranking Description: Programming Ability Test (PAT) is organized by the Colleg ...
- 1025 PAT Ranking (25分)
1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...
随机推荐
- .net关于httpModules的应用示例
这三个对象我们在开发Asp.net程序时经常会用到,似乎很熟悉,但有时 候又不太确定.本文通过一个简单的例子来直观的比较一下这三个对象的使用. HttpModule:Http模块,可以在页面处理前后. ...
- DBA_Oracle DBA常用表汇总(概念)
2014-06-20 Created By BaoXinjian
- 一个优秀的C#开源绘图软件 DrawTools
1.Extensions to DrawTools Author Mark Miller I develop software for a leading healthcare system in N ...
- 前端实现 SVG 转 PNG
http://fex.baidu.com/blog/2015/11/convert-svg-to-png-at-frontend/ 前言 svg 是一种矢量图形,在 web 上应用很广泛,但是很多时候 ...
- bug_ _fragment_“The specified child already has a parent. You must call removeView"的解决以及产生的原因
这个异常的出现往往是因为非法使用了某些方法引起的. 从字面意思上是说这个特定的child已经有一个parent了,你必须在这个parent中首先调用removeView()方法,才能继续你的内容.这里 ...
- AI
- Delphi的内存管理及内存泄露问题 FastMM4
这几天因为一个程序长时间运行出现比较严重的内存泄露问题,开始关注了一下内存管理方面的东西,以前也注意内存管理,创建了对象及时释放,但总有忘了处理的情况. 在Delphi中没有自动回收机制,所以一定要及 ...
- SVN提交数据失败问题(提示 svn:MKACTIVITY ... 403 Forbidden )
注册了淘宝svn,结果在代码提交是老是出问题,如下截图所示: 网上有常用的一种方法是: http://jingyan.baidu.com/article/67508eb4d3f2e29ccb1ce47 ...
- IOS学习之路- 运行过程
1. 执行Main函数(在main.m文件中) 2. 加载MainStoryborad.storyboard文件 * 创建ViewController文件 * 根据storyboard文件中描述创建V ...
- 通过srvctl add命令添加database信息到srvctl管理器-转
这是我在实际中遇到的一个问题,rac+dg架构将备库切为主库,srvctl管理器中没有database信息. 对于dbca创建的数据库,srvctl中包含了数据库和实例的信息.但是对于备份恢复的RAC ...