8 条题解

  • 1
    @ 2024-11-24 12:08:02

    #include<bits/stdc++.h> using namespace std; struct student{ int id,yw,sx,yy,sum; }a[505]; int cmp(student a,student b){ if(a.sum>b.sum) return 1; else if(a.sumb.sum&&a.yw>b.yw) return 1; else if(a.ywb.yw&&a.sum==b.sum&&a.id<b.id) return 1; else return 0; } int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i].yw>>a[i].sx>>a[i].yy; a[i].sum=a[i].yw+a[i].sx+a[i].yy; a[i].id=i; } sort(a+1,a+n+1,cmp); for(int i=1;i<=5;i++)cout<<a[i].id<<" "<<a[i].sum<<endl; return 0; }

    • 1
      @ 2024-11-23 18:36:33
      #include<bits/stdc++.h>
      using namespace std;
      struct student{
      	int id,yw,sx,yy,sum;
      }a[505];
      int cmp (student a,student b){
      	if(a.sum>b.sum) return 1;
      	else if(a.sum==b.sum&&a.yw>b.yw) return 1;
      	else if(a.yw==b.yw&&a.sum==b.sum&&a.id<b.id) return 1;
      	else return 0;
      }
      int main(){
      	int n;
      	cin>>n;
      	for(int i=1;i<=n;i++){
      		cin>>a[i].yw>>a[i].sx>>a[i].yy;
      		a[i].sum=a[i].yw+a[i].sx+a[i].yy;
      		a[i].id=i;
      	}
      	sort(a+1,a+n+1,cmp);
      	for(int i=1;i<=5;i++){
      		cout<<a[i].id<<" "<<a[i].sum<<endl;
      	}
      	for(int i=1;i<=3;i++)
      		break;
      	return 0;
      }
      
      • 0

        #include <stdio.h> #include <iostream> #include <bits/stdc++.h> using namespace std; struct student{ int num,yw,sx,yy,sum; string name; }a[10000]; int cmp(student a,student b) { if(a.sum>b.sum) { return 1; } else if(a.sumb.sum && a.yw>b.yw) { return 1; } else if(a.sumb.sum && a.yw==b.yw && a.num<b.num) { return 1; } else{ return 0; } } int main() { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i].yw>>a[i].sx>>a[i].yy; a[i].sum=a[i].yw+a[i].sx+a[i].yy; a[i].num=i;

        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=5;i++)
        {
        	cout <<a[i].num;
        	cout << " "<<a[i].sum<<endl;
        }
        

        }

        • 0
          @ 2024-11-3 14:14:59
          /*
          int      %o/%lo 8 %d/%i/%ld/%li 10 %x/%lx 16
          longlong %lld
          float    %f/%e
          double   %lf/%le
          char     %c
          char[]   %s
          'a'=97
          'z'=122
          'A'=65
          'Z'=90
          '0'=48
          '9'=57
          */
          #include <iostream>
          #include <iomanip>
          #include <cmath>
          #include <cstdio>
          #include <cstring>
          #include <algorithm>
          #include <ctime>
          #include <limits>
          #include <assert.h>
          #include <stdlib.h>
          using namespace std;
          #define LL long long
          #define ull unsigned long long
          const int N=1e5+10;
          const int INF=0x3f3f3f3f;
          const double pi=3.1416;
          int n;
          struct sb{
          	int c,m,e,t,id;
          }a[N];
          bool cmp(sb a1,sb a2){
          	if(a1.t==a2.t){
          		if(a1.c==a2.c){
          			return a1.id<a2.id;
          		}
          		return a1.c>a2.c;
          	}
          	return a1.t>a2.t;
          }
          int main(){
          	cin>>n;
          	for(int i=1;i<=n;i++){
          		cin>>a[i].c>>a[i].m>>a[i].e;
          		a[i].t=a[i].c+a[i].m+a[i].e;
          		a[i].id=i;
          	}
          	sort(a+1,a+n+1,cmp);
          	for(int i=1;i<=5;i++){
          		cout<<a[i].id<<" "<<a[i].t<<endl;
          	}
          return 0;
          }
          
          • 0
            @ 2024-3-17 20:27:49
            #include<bits/stdc++.h>
            using namespace std;
            const int N = 1e5 + 10;
            int n,k;
            struct stu
            {
            	int id;
            	int yw;
            	int sx;
            	int yy;
            	int total;
            }a[N];
            bool cmp(stu a1,stu a2)
            {
            	if(a1.total == a2.total)
            	{
            	    if(a1.yw == a2.yw)
            	    {
            	       a1.id < a2.id;
            	    }
            	    return a1.yw > a2.yw;
            	}
            	return a1.total > a2.total;
            }
            int main(){
                cin >> n >> k;
                for(int i = 1;i <= n;i++)
                {
                    cin >> a[i].id >> a[i].yw >> a[i].sx >> a[i].yy;
                    a[i].total = a[i].yw + a[i].sx + a[i].yy;
                    a[i].id = i;
                }
                sort(a + 1,a + n + 1,cmp);
                for (int i = 1;i <= 5;i++)
                    cout << a[k].id << " " << a[k].yw;
                return 0;
            }
            
            • 0
              @ 2024-3-17 18:38:27

              简约代码

              #include <iostream>//点个赞拿走 
              #include <algorithm>
              using namespace std;
              const int N = 1e5 + 10;
              int n,k;
              struct ikun{
              	int id , yu , shu , yin , to;
              }a[N];
              bool cmp(ikun a1,ikun a2){//想抄P1363的同学 。 
              	if (a1.to == a2.to)//记得删掉数学和英语。 
              	{
              		if (a1.yu == a2.yu)
              		{	
              			return a1.id < a2.id;
              		}
              		return a1.yu > a2.yu;
              	}
              	return a1.to > a2.to;
              } 
              int main(){
              	cin >> n;
              	for (int i = 1;i <= n;i++) 
              	{
              		cin >> a[i].yu >> a[i].shu >> a[i].yin;
              		a[i].to = a[i].yu + a[i].shu + a[i].yin;//总和 
              		a[i].id = i;
              		
              	}
              	sort(a+1,a+n+1,cmp);//自定义排序。 
              	for (int i = 1;i <= 5;i++)
              		cout << a[i].id << " " << a[i].to << endl;
              }
              
              • 0
                #include <iostream>
                #include <algorithm>
                using namespace std;
                int n;
                struct stu{
                	int chinese,maths,english;
                	int tot,id;
                };
                stu a[310];
                bool cmp(stu A,stu B){
                	if(A.tot!=B.tot)return A.tot>B.tot;
                	else if(A.chinese!=B.chinese)return A.chinese>B.chinese;
                	else return A.id<B.id;
                }
                int main(){
                	cin>>n;
                	for(int i=1;i<=n;i++){
                		cin>>a[i].chinese>>a[i].maths>>a[i].english;
                		a[i].tot=a[i].chinese+a[i].maths+a[i].english;
                		a[i].id=i;
                	}
                	sort(a+1,a+n+1,cmp);
                	for(int i=1;i<=5;i++){
                		cout<<a[i].id<<" "<<a[i].tot<<endl;
                	}
                }
                
                • 0
                  @ 2023-6-3 8:19:09

                  思路分析: 首先,读入n和每个学生的三门成绩,计算每个学生的总分,将学生信息存储在一个结构体数组中,然后按照总分、语文成绩、学号的顺序进行排序,最后输出前五名学生的学号和总分即可。

                  • 1

                  信息

                  ID
                  691
                  时间
                  1000ms
                  内存
                  256MiB
                  难度
                  5
                  标签
                  递交数
                  316
                  已通过
                  125
                  上传者