NoWalnut @ 2024-10-18 00:05:06
有没有dalao帮忙看看,我的第一个测试点怎么都过不去,已经考虑三个0的情况了,谢谢谢谢
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int N;
scanf("%d",&N);
getchar();
char s[50];
char name[N][20];
int a[N],b[N],c[N];
int sum[N];
int max=-1;
int std;
for(int i=0;i<N;i++){
fgets(s,sizeof(s),stdin);
sscanf(s,"%s %d %d %d",name[i],&a[i],&b[i],&c[i]);
sum[i]=a[i]+b[i]+c[i];
}
for(int j=0;j<N;j++){
if(sum[j]>max){max=sum[j];std=j;}
}
printf("%s %d %d %d",name[std],a[std],b[std],c[std]);
return 0;
}
by SunXiaolang @ 2024-10-18 06:17:07
@NoWalnut ```cpp
using namespace std; int main() { int yu,shu,yin,big=-1,n,b1,b2,b3; string name,i; cin>>n; for (int l=1;l<=n;l++){ cin>>name>>yu>>shu>>yin; if (yu+shu+yin>big) { big=yu+shu+yin; b1=yu; b2=shu; b3=yin; i=name; } } cout<<i<<" "<<b1<<" "<<b2<<" "<<b3; }
by SunXiaolang @ 2024-10-18 06:17:25
#include<bits/stdc++.h>
using namespace std;
int main() {
int yu,shu,yin,big=-1,n,b1,b2,b3;
string name,i;
cin>>n;
for (int l=1;l<=n;l++){
cin>>name>>yu>>shu>>yin;
if (yu+shu+yin>big) {
big=yu+shu+yin;
b1=yu;
b2=shu;
b3=yin;
i=name;
}
}
cout<<i<<" "<<b1<<" "<<b2<<" "<<b3;
}
by SunXiaolang @ 2024-10-18 06:18:21
你其实可以把判断放在第一个循环里
by SunXiaolang @ 2024-10-18 06:19:48
然后输入能用string,不用数组,接着后面三个数字用int来输入就行了
by NoWalnut @ 2024-10-18 09:08:26
@SunXiaolang ok,我明白了,非常感谢
by SunXiaolang @ 2024-10-18 20:16:37
@NoWalnut 求关
by NoWalnut @ 2024-10-29 21:16:35
@SunXiaolang 好