zkszks @ 2024-07-17 10:26:32
#include <iostream>
//#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
string n[10001][10001];
int main(){
int a,b[10001],c[10001],d[10001],m[10001];
cin>>a;
for(int i=0;i<a;i++){
cin>>n[i][10001]>>b[i]>>c[i]>>d[i];
m[i]=b[i]+c[i]+d[i];
for(int o=0;o<i;o++){
if(m[i]<m[o]){
swap(m[o],m[i]);
swap(n[o],n[i]);
swap(b[o],b[i]);
swap(c[o],c[i]);
swap(d[o],d[i]);
}
}
}
cout<<n[a-1][10001]<<" "<<b[a-1]<<" "<<c[a-1]<<" "<<d[a-1];
}
//1090k 364x=n
//x x+k,x+2k x+3k x+4k x+5k x+6k 52(21k+7x)=1456
//21k+7x=119
by zkszks @ 2024-07-17 10:27:36
注释忽略不理,因为我一个cpp文件用好几次,然后写的一些注释
by Cailen @ 2024-07-17 10:32:51
把n数组改成一维的,后面的[10001]删掉,输入时输入n[i],其他不用动
by fire_flies @ 2024-07-17 10:33:26
@zkszks 结构体+排序
#include<bits/stdc++.h>
#include<string>
using namespace std;
struct student{
string name;
int a,b,c,d;
};
student a[1005];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].name;
cin>>a[i].a>>a[i].b>>a[i].c;
a[i].d=a[i].a+a[i].b+a[i].c;
}
for(int i=n-1;i>0;i--){
for(int j=1;j<=i;j++){
if(a[j].d<a[j+1].d){
swap(a[j],a[j+1]);
}
}
}
cout<<a[1].name<<" "<<a[1].a<<" "<<a[1].b<<" "<<a[1].c;
return 0;
}
求关注
by fire_flies @ 2024-07-17 10:34:33
@zkszks 可以试试用结构体来储存变量
by Maisie586_ @ 2024-07-17 10:40:30
@zkszks 求关
#include <bits/stdc++.h>
using namespace std;
struct abc{
string name;
int all_subject,chinese,math,english;
int id;
}a[11100];
bool cmp(abc a,abc b)
{
if(a.all_subject==b.all_subject){
return a.id<b.id;
}
return a.all_subject>b.all_subject;
}
int main() {
int t1,t2,t3;
int n;
string s;
cin >> n;
for(int i=1;i<=n;i++){
cin >>s>> t1 >> t2 >> t3;
a[i].name = s;
a[i].chinese = t1;
a[i].math = t2;
a[i].english = t3;
a[i].all_subject=t1+t2+t3;
a[i].id=i;
}
sort(a+1,a+1+n,cmp);
cout << a[1].name << " "<<a[1].chinese;
cout << " " << a[1].math << " " << a[1].english;
}
by zkszks @ 2024-07-17 11:19:37
@fire_flies 我试试
by zkszks @ 2024-07-17 11:20:55
@Cailen 我看看