4 条题解

  • 1
    @ 2024-8-10 12:56:40

    结构体练手~

    #include<bits/stdc++.h>
    using namespace std;
    
    struct ac{
        string name;
        int s;
    }a[11];
    
    bool c(ac a,ac b){
        return a.s<b.s;
    }
    
    int main(){
        int n;
        cin>>n;
        for(int i=0;i<n;i++) cin>>a[i].name>>a[i].s;
        sort(a,a+n,c);
        if(a[0].s>=100){
            cout<<"died!";
            return 0;
        }
        if(a[0].s<100){
            cout<<a[0].name;
            return 0;
        }
    }
    
    • 0
      @ 2024-8-1 12:07:23

      #include<bits/stdc++.h> using namespace std; typedef struct{ string name; int g; }fengnai; bool cmp(fengnai a,fengnai b) { return a.g<b.g; } int main(){ int n; cin>>n; fengnai f[n]; for(int i=0;i<n;i++){ cin>>f[i].name>>f[i].g; } sort(f,f+n,cmp); if(f[0].g>=100){ cout<<"died!";} else{ cout<<f[0].name; } }

      • 0
        @ 2024-7-4 11:01:03
        #include<bits/stdc++.h>
        using namespace std;
        typedef struct{
            string name;
            int g;
        }fengnai;
        bool cmp(fengnai a,fengnai b)
        {
            return a.g<b.g;
        }
        int main(){
            int n;
            cin>>n;
            fengnai f[n];
            for(int i=0;i<n;i++){
                cin>>f[i].name>>f[i].g;
            }
            sort(f,f+n,cmp);
        	        if(f[0].g>=100){
        	            cout<<"died!";}
        	        else{
        	            cout<<f[0].name;
        	        }
        }
        
        • 0
          @ 2024-1-30 17:45:50

          #include<bits/stdc++.h> using namespace std; struct fn{ string mz; int jl; }; int main(){ fn a[11]; int n,minn=10005,dg; cin>>n; for(int i=0;i<n;i++){ cin>>a[i].mz>>a[i].jl; if(minn>a[i].jl){ minn=a[i].jl; dg=i; } } if(minn<100){ cout<<a[dg].mz; } else{ cout<<"died!"; } } 没加换行,自己加上;复杂度是O(n),应该挺好

          • 1

          信息

          ID
          484
          时间
          1000ms
          内存
          256MiB
          难度
          7
          标签
          递交数
          252
          已通过
          66
          上传者