liuzixuancluo @ 2024-11-04 18:49:53
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv) {
int n;
cin>>n;
string a[1001];
int b[1001];
int c[1001];
int d[1001];
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i]>>c[i]>>d[i];
}
int m=0;
for(int i=1;i<=n;i++)
{
int t;
t=d[i]+b[i]+c[i];
if(t>m)
{
m=t;
}
}
for(int i=1;i<=n;i++)
{
if(b[i]+c[i]+d[i]==m)
{
cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<" "<<d[i];
}
}
return 0;
}
by 4399__ @ 2024-11-09 20:34:02
如果有多个相同,会都输出,改如下
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv) {
int n;
cin>>n;
string a[1001];
int b[1001];
int c[1001];
int d[1001];
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i]>>c[i]>>d[i];
}
int m=0;
for(int i=1;i<=n;i++)
{
int t;
t=d[i]+b[i]+c[i];
if(t>m)
{
m=t;
}
}
for(int i=1;i<=n;i++)
{
if(b[i]+c[i]+d[i]==m)
{
cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<" "<<d[i];
return 0;//有合适的直接走
}
}
}