半成品代码(自的学,写不好)

#include<bits/stdc++.h>
using namespace  std;
int n,zf[1005],id[1005],yw[1005],sx[1005],ey[1005],wu[1005],hu[1005],bjg;
struct student
{
    int id;
    string na;
    int ch,ma,en,wl,hx;
}; 
string name[1005];
int  main( ) 
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        student st;
        cin>>st.id>>st.na>>st.ch>>st.ma>>st.en>>st.wl>>st.hx;
        id[i]=st.id;
        name[i]=st.na;
        yw[i]=st.ch;
        sx[i]=st.ma;
        ey[i]=st.en;
        wu[i]=st.wl;
        hu[i]=st.hx;
        zf[i]=st.ch+st.ma+st.en+st.wl+st.hx;    
        if (yw[i]<60 || sx[i]<60 || ey[i]<60 || wu[i]<60 || hu[i]<60)
            bjg++;
    }
    cout<<bjg<<endl;
    sort(zf+1,zf+1+n,);
    for (int i=1;i<=n;i++)
        cout<<id[i]<<' '<<name[i]<<" "<<yw[i]<<' '<<sx[i]<<" "<<ey[i]<<' '<<wu[i]<<" "<<hu[i]<<' '<<zf[i]<<endl;
    return 0;   
}

5 条评论

  • #include<bits/stdc++.h>
    using namespace  std;
    int n,ans;
    struct student
    {
        string na;
        int id,sum,a,b,c,d,e;
    }st[1005]; 
    string name[1005];
    int  main( ) 
    {
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>st[i].id>>st[i].na>>st[i].a>>st[i].b>>st[i].c>>st[i].d>>st[i].e;
            if (st[i].a<60 || st[i].b<60 || st[i].c<60 || st[i].d<60 || st[i].e<60)
            ans++;
            st[i].sum=st[i].a+st[i].b+st[i].c+st[i].d+st[i].e;
        }
        for (int i=1;i<n;i++)
            for (int j=i+1;j<=n;j++)
            {
                if (st[i].sum<st[j].sum)
                    swap(st[i],st[j]);
                else if (st[i].sum==st[j].sum)
                    if (st[i].a<st[j].a)
                        swap(st[i],st[j]);
            }
        cout<<ans<<endl;
        if (n>20)
            n=20;
        for (int i=1;i<=n;i++)
            cout<<st[i].id<<" "<<st[i].na<<' '<<st[i].a<<" "<<st[i].b<<' '<<st[i].c<<" "<<st[i].d<<' '<<st[i].e<<" "<<st[i].sum<<endl;
        return 0;   
    }
    
    
  • #include<bits/stdc++.h>
    using namespace std;
    struct stu{
        int num, a[5], total;
        string name;
    }s[1010];
    bool cmp(stu x, stu y){
        if(x.total != y.total)return x.total > y.total;
        else return x.a[0] > y.a[0];
    }
    int main(){
        ios::sync_with_stdio(false);
        int q, cnt = 0;
        cin >> q;
        for(int i = 1; i <= q; i++){
            cin >> s[i].num >> s[i].name;
            for(int j = 0; j <= 4; j++)cin >> s[i].a[j];
            s[i].total = s[i].a[0]+s[i].a[1]+s[i].a[2]+s[i].a[3]+s[i].a[4];
            if(s[i].a[0]<60 || s[i].a[1]<60 || s[i].a[2]<60 || s[i].a[3]<60 || s[i].a[4]<60)cnt++;
        }
        sort(s+1, s+q+1, cmp);
        q = min(q, 20);
        cout << cnt << endl;
        for(int i = 1; i <= q; i++){
            cout << s[i].num << ' ' << s[i].name << ' ';
            for(int j = 0; j <= 4; j++)cout << s[i].a[j] << ' ';
            cout << s[i].total << endl;
        }
        return 0;
    }
    
    
  • #include<bits/stdc++.h>
    using namespace  std;
    int n,zf[1005],id[1005],yw[1005],sx[1005],ey[1005],wu[1005],hu[1005],bjg;
    struct student
    {
        int id;
        string na;
        int ch,ma,en,wl,hx;
    }; 
    string name[1005];
    int  main( ) 
    {
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            student st;
            cin>>st.id>>st.na>>st.ch>>st.ma>>st.en>>st.wl>>st.hx;
            id[i]=st.id;
            name[i]=st.na;
            yw[i]=st.ch;
            sx[i]=st.ma;
            ey[i]=st.en;
            wu[i]=st.wl;
            hu[i]=st.hx;
            zf[i]=st.ch+st.ma+st.en+st.wl+st.hx;    
            if (yw[i]<60 || sx[i]<60 || ey[i]<60 || wu[i]<60 || hu[i]<60)
                bjg++;
        }
        cout<<bjg<<endl;
        sort(zf+1,zf+1+n,);
        for (int i=1;i<=n;i++)
            cout<<id[i]<<' '<<name[i]<<" "<<yw[i]<<' '<<sx[i]<<" "<<ey[i]<<' '<<wu[i]<<" "<<hu[i]<<' '<<zf[i]<<endl;
        return 0;   
    }
    
    
  • @ 2026-07-18 17:50:09

    我去,结构体你都会了

  • 求大佬修改指正

  • 1

信息

ID
1005
难度
5
分类
(无)
标签
递交数
212
已通过
68
通过率
32%
被复制
11
上传者