lizesheng520 @ 2024-02-02 10:23:47
本地直接停止工作。
#include<bits/stdc++.h>
using namespace std;
struct student {
string name;
int score[3];
int sum;
};
int main() {
int maxn=0,maxcnt,n,scores[3] = {0};
student temp[105];
for(int i=0; i<n; i++) {
cin>>temp[i].name;
temp[i].score[i] = {0};
for(int j=0; j<3; j++) {
cin>>scores[j];
temp[i].score[j]=scores[j];
}
}
for(int i=0; i<n; i++) {
temp[i].sum=0;
temp[i].sum=temp[i].score[0]+temp[i].score[1]+temp[i].score[2];
}
for(int i=0; i<n; i++) {
if(temp[i].sum>maxn) {
maxn=temp[i].sum;
maxcnt = i;
}
}
cout<<temp[maxcnt].name<<" ";
cout<<temp[maxcnt].score[0]<<" "<<temp[maxcnt].score[1]<<" "<<temp[maxcnt].score[2];
return 0;
}
救救萌新吧
by Cuber_release @ 2024-02-02 10:31:07
没有输入变量n
而且n在主函数内定义
引用未定义变量会RE
by Cuber_release @ 2024-02-02 10:31:41
#include<bits/stdc++.h>
using namespace std;
struct student {
string name;
int score[3];
int sum;
};
int main() {
int maxn=0,maxcnt,n,scores[3] = {0};
cin >> n; // 初始化 n
student temp[105];
for(int i=0; i<n; i++) {
cin>>temp[i].name;
temp[i].score[i] = {0};
for(int j=0; j<3; j++) {
cin>>scores[j];
temp[i].score[j]=scores[j];
}
}
for(int i=0; i<n; i++) {
temp[i].sum=0;
temp[i].sum=temp[i].score[0]+temp[i].score[1]+temp[i].score[2];
}
for(int i=0; i<n; i++) {
if(temp[i].sum>maxn) {
maxn=temp[i].sum;
maxcnt = i;
}
}
cout<<temp[maxcnt].name<<" ";
cout<<temp[maxcnt].score[0]<<" "<<temp[maxcnt].score[1]<<" "<<temp[maxcnt].score[2];
return 0;
}