当前位置:网站首页>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 pioneer futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?
- Examples of bubble sorting and matrix element screening in MATLAB
- [untitled]
- Forward declaration of classes
- How to use Alibaba Vector Icon
- 高清机械原理 · 机械设计经典动图
- V3 02——What‘s new in Chrome extensions
- [buuctf] [geek challenge 2019] secret file
- Text matching - [naacl 2022] GPL
- Greedy two-dimensional array sorting
猜你喜欢

PS dynamic drawing

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

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

2021-05-12

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

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

Learn about data kinship JSON format design from sqlflow JSON format

Laravel upload error

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

CCF numerical sorting (Full Score code + problem solving ideas + skill summary) 201503-2
随机推荐
Binary rotation array (2)
Vue returns to the previous page without refreshing the page / Vue caches the page
[buuctf] [actf2020 freshman competition]exec1
How does hbuilder display in columns?
机械工程师面试的几个问题,你能答上来几个?
[extensive reading of papers] a delicious recipe analysis framework for exploring multi modal recipes with variable attributes
1 figure to explain the difference and connection between nodejs and JS
For loop and promise to solve the problem of concurrent callback
Finding the median of two arrays by dichotomy
ThinkPHP v3.2 comment annotation injection write shell
JS time conversion standard format, timestamp conversion standard format
Problem: wechat developer tool visitor mode cannot use this function
[extensive reading of papers] multimodal joint attribute prediction and value extraction for e-commerce product
Add attributes to multimode
Is pioneer futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?
1135: paired base chain
PHP recursive multi-level classification, infinite classification
CCF drawing (full mark code + problem solving ideas + skill summary) February 2, 2014
Judgment of deep learning experiment results
【BUUCTF】 EasySql