moclocd 2022-12-24 14:09 采纳率: 92.9%
浏览 25
已结题

#c++#看看哪里错了,总是不输出

描述
某班级有n个学生,现在要在该班级中挑选出优秀生,所有的学生需要参加四轮竞赛,每轮竞赛的总分是100分,由于竞赛难度较大,四轮的总分能达到200分的就是优秀生,请你依次输出优秀生的信息,最后一行输出在该班级选出的优秀生的人数。

输入
第一行:n,n<200

接下来n行:每行五个数,第一个数字为学号,后面的四个数字为四轮竞赛的得分

输出
先输出所有选出的优秀生的信息,包括学号和四轮竞赛的得分

最后一行输出在该班级选出的优秀生的人数

输入样例 1
4
1947 54 43 52 59
2848 57 43 50 56
4687 60 49 45 48
4955 41 46 43 50
输出样例1
1947 54 43 52 59
2848 57 43 50 56
4687 60 49 45 48
3
我的代码:

#include<bits/stdc++.h>
using namespace std;
struct student{
    int xha;
    int j1;
    int j2;
    int j3;
    int j4;
}stu5;
int main(){
    int xh;
    int jing1;
    int jing2;
    int jing3;
    int jing4;
    int i,n,cnt=0;
    cin>>n;
    struct student stu1[550];
    stu1[550].xha;
    stu1[550].j1;
    stu1[550].j2;
    stu1[550].j3;
    stu1[550].j4;
    for(i=1;i<=n;i++){
        cin>>xh>>jing1>>jing2>>jing3>>jing4;
    stu1[i].xha=xh;
    stu1[i].j1=jing1;
    stu1[i].j2=jing2;
    stu1[i].j3=jing3;
    stu1[i].j4=jing4;
    }
    for(i=1;i<=n;i++){
        if(stu1[i].j1+stu1[i].j2+stu1[i].j3+stu1[i].j4==200){
            cout<<stu1[i].xha<<" "<<stu1[i].j1<<" "<<stu1[i].j2<<" "<<stu1[i].j3<<" "<<stu1[i].j4<<endl;
            cnt++;
        }
    }
    cout<<cnt;
    return 0;
}
  • 写回答

2条回答 默认 最新

  • 小6的跟班 2022-12-24 14:36
    关注
    
    #include<bits/stdc++.h>
    using namespace std;
    struct student{
        int xha;
        int j1;
        int j2;
        int j3;
        int j4;
    }stu1;
    int main(){
        int xh;
        int jing1;
        int jing2;
        int jing3;
        int jing4;
        int i,n,cnt=0;
        cin>>n;
        struct student stu1[550];
        stu1[550].xha;
        stu1[550].j1;
        stu1[550].j2;
        stu1[550].j3;
        stu1[550].j4;
        for(i=0;i<n;i++){
            cin>>xh>>jing1>>jing2>>jing3>>jing4;
        stu1[i].xha=xh;
        stu1[i].j1=jing1;
        stu1[i].j2=jing2;
        stu1[i].j3=jing3;
        stu1[i].j4=jing4;
        }
        for(i=0;i<n;i++){//数组下标从0开始
            if((stu1[i].j1+stu1[i].j2+stu1[i].j3+stu1[i].j4)>=200){//判断条件要大于等于200
                cout<<stu1[i].xha<<" "<<stu1[i].j1<<" "<<stu1[i].j2<<" "<<stu1[i].j3<<" "<<stu1[i].j4<<endl;
                cnt++;
            }
        }
        cout<<cnt;
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月1日
  • 已采纳回答 12月24日
  • 创建了问题 12月24日

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值