1 条题解

  • 0
    @ 2021-6-15 1:39:14

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    struct student{
        int a,b,c;
        int num,ans;
    };
    student s[101];
    bool comp(student x,student y){
        if(x.ans!=y.ans) return x.ans>y.ans;
        if(x.a!=y.a) return x.a>y.a;
        return x.num<y.num;
    }
    int main(){
        int i,n;
        scanf("%d",&n);
        for(i=1;i<=n;i++){
            scanf("%d%d%d",&s[i].a,&s[i].b,&s[i].c);
            s[i].ans=s[i].a+s[i].b+s[i].c;
            s[i].num=i;
        }
        sort(s+1,s+1+n,comp);
        for(i=1;i<6;i++)
            printf("%d %d\n",s[i].num,s[i].ans);
        return 0;
    }
    

    Pascal :

    var x,a,d:array[0..300]of longint;n,i,j,b,c,t:longint; 
    begin
     read(n); 
     for i:=1 to n do
      begin
       read(a[i],b,c); 
       x[i]:=a[i]+b+c; 
       d[i]:=i; 
      end; 
     for i:=1 to n-1 do
      for j:=i+1 to n do
       if (x[i]<x[j])or(x[i]=x[j])and(a[i]<a[j]) 
          or(x[i]=x[j])and(a[i]=a[j])and(d[i]>d[j])then
           begin
            t:=a[i];a[i]:=a[j];a[j]:=t; 
            t:=x[i];x[i]:=x[j];x[j]:=t; 
            t:=d[i];d[i]:=d[j];d[j]:=t; 
           end; 
     for i:=1 to 5 do writeln(d[i],' ',x[i]); 
    end.
    
    • 1

    信息

    ID
    253
    时间
    1000ms
    内存
    125MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者