当前位置:网站首页>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;
}
边栏推荐
- Is it troublesome for CITIC futures to open an account? Is it safe? How much is the handling charge for opening an account for futures? Can you offer a discount
- Matlab calculates the factorial sum of the first n numbers (easy to understand)
- val_ Loss decreases first and then increases or does not decrease but only increases
- Ctfshow getting started with the web (ThinkPHP topic)
- Average and maximum values of MATLAB matrix
- 2021-07-14 mybaitsplus
- Maximum area of islands searched
- Implement a long-click list pop-up box on apiccloud
- Computer screenshot how to cut the mouse in
- V3 02——What‘s new in Chrome extensions
猜你喜欢

Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications

ctfshow nodejs

PS cutting height 1px, Y-axis tiling background image problem

Matlab construction operation example

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

【BUUCTF】 Have Fun
![[buuctf] [actf2020 freshman competition]include](/img/42/50439290177fdea5f431e315cac1a1.jpg)
[buuctf] [actf2020 freshman competition]include

PS dynamic drawing

Shift operator (detailed)

V3 03_ Getting started
随机推荐
Using member variables and member functions of a class
The first dark spring cup dnuictf
PS cutting height 1px, Y-axis tiling background image problem
2021-08-07 native and package types
Judgment of deep learning experiment results
左旋梯形螺纹的编程
Repair of incorrect deletion of win10 boot entry
CCF image rotation (Full Score code + problem solving idea) 201503-01
CCF Z-scan (full mark code + problem solving ideas) 201412-2
DR-TANet: Dynamic Receptive Temporal Attention Network for Street Scene Change Detection
Upgrade centos7 mysql5.5 to mysql5.7 non RPM in the form of tar package
ES6 notes
Finding the median of two arrays by dichotomy
Analysis on the problems of irregular step hole on horizontal machining center
Hbuilder most commonly used and full shortcut key set
[extensive reading of papers] sentimental analysis of online reviews with a hierarchical attention network
Clear the route cache in Vue
1135: paired base chain
Matlab calculates the factorial sum of the first n numbers (easy to understand)
JS to realize simple lottery function