分数线划定

此博客展示了一段C++代码,用于处理学生成绩数据。代码定义结构体存储学生ID和成绩,通过冒泡排序算法对学生按成绩降序、ID升序排序,计算入围人数,筛选出入围学生并输出入围分数线、入围人数及入围学生信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#include<cstdio>
    struct node{
    int score;
    int id;
    };
    node student[5500];
int main()
{
    int n,m,ruwei,i,j,cnt=0;
    cin>>n>>m;
    ruwei=floor(m*1.5);
    for(i=1;i<=n;i++)
        cin>>student[i].id>>student[i].score;
    for(i=n-1;i>=1;i--)
        for(j=1;j<=i;j++)//条件需要写清楚,这里很容易出错,冒泡法排序的起点和终点需要明确,便利很容易超出范围
        {
            if(student[j].score<student[j+1].score)            
            swap(student[j],student[j+1]);
            else if((student[j].score==student[j+1].score)&&(student[j].id>student[j+1].id))
            swap(student[j],student[j+1]);
        }    
    for(i=1;i<=n;i++)
        if(student[i].score>=student[ruwei].score) 
        {
            cnt++;        
        }
        cout<<student[ruwei].score<<" "<<cnt<<endl;
        for(i=1;i<=cnt;i++)
        cout<<student[i].id<<" "<<student[i].score<<endl;
        return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值