当前位置:网站首页>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;
}
边栏推荐
- JS to realize simple lottery function
- 1137: encrypted medical record
- Average and maximum values of MATLAB matrix
- Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications
- V3 01_ Welcome
- [extensive reading of papers] analyzing connections between user attributes, images, and text
- How to use Alibaba Vector Icon
- Thinkphp5 log file contains trick
- Finding the median of two arrays by dichotomy
- 分布式--OpenResty+lua+Redis
猜你喜欢

August 24, 2021 deque queue and stack

Att & CK red team evaluation field (I)

Shangpinhui knowledge points of large e-commerce projects

2021-07-14 mybaitsplus
![【BUUCTF】[GXYCTF2019]Ping Ping Ping1](/img/dc/4d87dfb0c2fa9cd75b54e092fd3971.jpg)
【BUUCTF】[GXYCTF2019]Ping Ping Ping1

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

@PathVariable

How does hbuilder display in columns?

2021 geek challenge Web

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
随机推荐
Greedy two-dimensional array sorting
Average and maximum values of MATLAB matrix
高精度CNC加工中心为什么会出现误差?这4个原因你要注意!
@PathVariable
Matlab finds prime numbers within 100
Matlab two-dimensional array example (extract data)
Lfi-rce without controllable documents
Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
Ctfshow getting started with the web (ThinkPHP topic)
NoViableAltException([email protected][])
Three ways and differences of defining functions in JS
CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3
ThinkPHP show method parameter controllable command execution
IO interview questions
1131: genetic correlation
高清机械原理 · 机械设计经典动图
Minimum covering substring of two pointers
ThinkPHP v3.2 comment annotation injection write shell
The difference between settimeout() and setinterval()
Is pioneer futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?