当前位置:网站首页>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;
}
边栏推荐
- Examples of bubble sorting and matrix element screening in MATLAB
- ThinkPHP v3.2 comment annotation injection write shell
- Greedy interval problem (5)
- K high frequency elements before sorting
- After the MySQL service on the local computer is started and stopped, some services will automatically stop when they are not used by other services or programs
- Text matching - [naacl 2021] augsbert
- Sorting by character frequency
- JS delete the objects in the array and specify to delete the objects
- Laravel upload error
- Knowledge learned from the water resources institute project
猜你喜欢

Solve the problem that codeblocks20.03 on win11 cannot run for the first time

CCF sequence segmentation (Full Score code + problem solving idea) 201509 -1

CCF access control system (Full Score code + problem solving idea) 201412-1

CCF string matching (Full Score code + problem solving ideas + skill summary) March 3, 2014

val_ Loss decreases first and then increases or does not decrease but only increases

KnightCTF WEB

CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3

LIS error: this configuration section cannot be used in this path

Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~

CCF Z-scan (full mark code + problem solving ideas) 201412-2
随机推荐
[extensive reading of papers] a delicious recipe analysis framework for exploring multi modal recipes with variable attributes
Solve the problem that codeblocks20.03 on win11 cannot run for the first time
2021-07-14 mybaitsplus
Matlab construction operation example
[buuctf] [geek challenge 2019] secret file
Basic requirements for tool use in NC machining of vertical machining center
PS dynamic drawing
The difference between queue and stack
DiceCTF - knock-knock
PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available
1130: find the first character that appears only once
Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications
Distributed -- openresty+lua+redis
Att & CK red team evaluation field (I)
HD mechanical principle · classic dynamic drawing of mechanical design
Win10 backup backup shows that creating a shared protection point on the shadow failed
ES6 notes
KnightCTF WEB
【BUUCTF】 Have Fun
Using member variables and member functions of a class