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. 代码 ...
随机推荐
- MongoDB 3.0.6的主,从,仲裁节点搭建
在MongoDB所在路径创建log和data目录mkdir logmkdir data 在data目录下 创建master.slaver.arbiter路径 mkdir master mkdir sl ...
- RAC_Oracle集群服务安装Grid Infrastructure(案例)
2015-01-24 Created By BaoXinjian Thanks and Regards
- DBA_Oracle Audit基本概念(概念)
2014-08-15 Created By BaoXinjian
- xpath提取目录下所有标签内的内容,递归 //text()
利用xpath来提取所有标签里面的内容,即使标签头不同 #-*-coding:utf8-*- import re import os from lxml import etree html = ''' ...
- REST架构实质(转)
REST(Representational State Transfer) 曾经被误解为只是CRUD(增删改查),从这个层面上,好像REST只是和RPC一个层面的东西,没有什么了不起,其实这些都是对R ...
- JAVA 流式布局管理器
//流式布局管理器 import java.awt.*; import javax.swing.*; public class Jiemian2 extends JFrame{ //定义组件 JBut ...
- linux安装iscsi target,make时出错,解决方法
安装主要是按照这个网址的步骤来的:http://ixdba.blog.51cto.com/2895551/526452 执行到make步骤时,出错: root@host:~/iscsitarget-1 ...
- VisualStudio使用小技巧——快捷键(转)
1. 怎样调整代码排版的格式?选择:编辑—>高级—>设置文档的格式或编辑—>高级—>设置选中代码的格式.格式化cs代码:Ctrl+k+f 格式化aspx代码:Ctrl+k+d2 ...
- codeblocks安装后无法编译
codeblocks安装后无法编译: 解决办法: 1.下载自带编译器的codeblock安装包. 2.安装完后.修改配置 (1)打开软件,选择setting->Compiler (2)在编译器设 ...
- [ActionScript 3.0] AS3 实现XML转换成JSON
package com.fylib.util { /** * @author Frost.Yen * @E-mail 871979853@qq.com * @create 2015-6-18 下午2: ...