当前位置:网站首页>1025 pat ranking (25 points)
1025 pat ranking (25 points)
2022-06-30 14:54:00 【Xue Dongjing】
1025 PAT Ranking (25 branch )
The question
give n A set of , Each group has k Row number , Yes k Sort by the number of rows .
Number of rows :id achievement
Sort rule : In descending order of grades , With the same score, press id Ascending order .
Sorting needs to give each id Number of groups ( Which group ), Global ranking and local ranking ( Ranking within the group )
Ideas
There are sorting in the structure .
Local rankings can use additional arrays to record scores and rankings .
Be careful id It's best to use a string to represent .
There may be more than one score for 0 People who .
Code
#include<algorithm>
#include<stdio.h>
#include<map>
#include<iostream>
#include<string.h>
using namespace std;
typedef struct node{
int v2,z,v;
string id;
}node;
node x1[300007];
map<string,int>name;
map<int,string>number;
int Count=0;
bool cmp(node a,node b)
{
if(a.v==b.v){
return a.id<b.id;
}else{
return a.v>b.v;
}
}
int chang(string x)
{
if(name.find(x)!=name.end()){
return name[x];
}else{
name[x]=Count;
number[Count]=x;
return Count++;
}
}
int main()
{
int n,k,v,p,temp,w,aa,bb,x2[307],x3[307],x4[307];
string id;
memset(x2,0,sizeof(x2));
memset(x3,-1,sizeof(x3));// Someone's score is 0, So it's initialized to -1
memset(x4,0,sizeof(x4));
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&k);
for(int j=0;j<k;j++){
cin>>id>>v;
p=chang(id);
if(j==0){
temp=p;
}
x1[p].id=id;
x1[p].v=v;
x1[p].z=i;
}
}
sort(x1,x1+Count,cmp);
printf("%d\n",Count);
for(int i=0;i<Count;i++){
if(x1[i].v==w&&i!=0){
aa=bb;
}else{
aa=i+1;
w=x1[i].v;
bb=aa;
}
if(x1[i].v==x3[x1[i].z]&&x3[x1[i].z]!=-1){
//x3 Initialize to 0 There may be a problem here
x1[i].v2=x4[x1[i].z];
}else{
x1[i].v2=x2[x1[i].z];
}
x3[x1[i].z]=x1[i].v;
x4[x1[i].z]=x1[i].v2;
x2[x1[i].z]++;
cout<<x1[i].id<<" "<<aa<<" "<<x1[i].z<<" "<<x1[i].v2+1<<endl;
}
return 0;
}
边栏推荐
- 【BUUCTF】 EasySql
- 数控加工中心打刀缸工作原理及故障处理
- JS array sorting method summary
- How to use Alibaba Vector Icon
- Matlab construction operation example
- Text matching - [naacl 2021] augsbert
- catkin_ Make reports an error, transfers the location of the workspace, and uses other people's workspace files to cause compilation errors
- CCF sequence segmentation (Full Score code + problem solving idea) 201509 -1
- CCF command line options (Full Score code + problem solving ideas + skill summary) March 3, 2014
- Greedy two-dimensional array sorting
猜你喜欢

【BUUCTF】 Have Fun

Error $(...) size is not a function

DefCamp Capture the Flag (D-CTF) 2021-22 web

ES6 notes

ThinkPHP show method parameter controllable command execution

Sum of CCF digits (full mark code + problem solving idea) 201512-1
![[buuctf] [actf2020 freshman competition]include](/img/42/50439290177fdea5f431e315cac1a1.jpg)
[buuctf] [actf2020 freshman competition]include

Learn about data kinship JSON format design from sqlflow JSON format

CCF numerical sorting (Full Score code + problem solving ideas + skill summary) 201503-2

2021 geek challenge Web
随机推荐
V3 03_ Getting started
Binary rotation array (2)
Programming of left-hand trapezoidal thread
Pseudocode writing specification
Att & CK red team evaluation field (I)
@PathVariable
1134: Legal C identifier query
Shangpinhui knowledge points of large e-commerce projects
JS time conversion standard format, timestamp conversion standard format
Matlab construction operation example
Basic requirements for tool use in NC machining of vertical machining center
Matlab finds prime numbers within 100
Sum of CCF digits (full mark code + problem solving idea) 201512-1
Binary rotation array (1)
[extensive reading of papers] attributes guided facial image completion
2021-08-05 leetcode notes
Maximum area of islands searched
JS array sorting method summary
[untitled]
Vue returns to the previous page without refreshing the page / Vue caches the page