A題題解:https://blog.csdn.net/Richard_1101/article/details/109263490
定義一個結構體存名字和速度,按速度排序輸出
#include<bits/stdc++.h>
using namespace std;
struct node{
string name;
long long speed;
}a[100001];
long long n,l;
bool cmp(node a,node b){
return a.speed<b.speed;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>l;
for(int i=0;i<n;i++)cin>>a[i].name>>a[i].speed;
sort(a,a+n,cmp);
for(int i=0;i<n-1;i++)cout<<a[i].name<<" "<<(i+1)*a[i].speed/l<<" "<<l-((i+1)*a[i].speed%l)<<endl;
cout<<a[n-1].name<<endl;
return 0;
}
也很簡單