7 solutions

  • 4
    @ 2023-10-28 16:46:40
    #include<bits/stdc++.h>
    using namespace std;
    int n,k;
    struct exam{
    	long long no;
    	double sc;
    };
    bool a(exam x,exam y){
    	return !(x.sc<y.sc);
    }
    int main(){
    	cin>>n>>k;
    	exam s[105];
    	for(int i=0;i<n;i++){
    		cin>>s[i].no>>s[i].sc;
    	}
    	sort(s,s+n,a);
    	cout<<s[k-1].no<<' '<<s[k-1].sc;
    	return 0;
    }
    

    烧脑

  • 1
    @ 2024-12-9 21:50:47
    #include<bits/stdc++.h>
    using namespace std;
    int n,k;
    struct cs{
       long long numb;
       double fen;
    };
    cs ex[110];//一定要定义在外面不然会神秘Ac8Wa2
    int sorrt(cs a,cs b){
       if(a.fen==b.fen and a.numb>b.numb){swap(a.numb,b.numb);return 1;}
       else if(a.fen>b.fen){swap(a.numb,b.numb); return 1;}
       else return 0;
    }
    int main(){
       cin>>n>>k;
       for(int i=0;i<n;i++){
          cin>>ex[i].numb;
          cin>>ex[i].fen;
          sort(ex,ex+n,sorrt);
       }
       cout<<ex[k-1].numb<<' '<<ex[k-1].fen;
       return 0;
    }
    
    • 1
      @ 2023-9-27 16:39:34
      #include <bits/stdc++.h>
      #include <algorithm>
      using namespace std;
      struct student{
      	int no;
      	float score;
      };
      bool cmp(student b,student c){
      	if (b.score < c.score){
      		return false;
      	}else{
      		return true;
      	}
      }
      int main(int argc, char **argv){
      	int n,k;student s[105];
      	cin >> n >> k;
      	for (int i = 0;i < n;i++){
      		cin >> s[i].no >> s[i].score;
      	}
      	sort(s,s + n,cmp);
      	printf("%d %g",s[k - 1].no,s[k - 1].score);
      	return 0;
      }
      
      • 0
        @ 2024-11-22 18:45:09
        //数组版
        #include <bits/stdc++.h>
        using namespace std;
        int n, k;
        int id[111];//名字 
        double score[111];//分数 
        int main()
        {
        	cin >> n >> k;
        	for(int i = 0; i < n; i++)
        	{
        		cin >> id[i] >> score[i];
        	}
        	for(int i = 0; i < n; i++)
        	{
        		for(int j = 0; j < n-i-1; j++)//n-i-1,只和前面的比 
        		{
        			if(score[j] < score[j+1])//成绩更高 
        			{
        				swap(score[j], score[j+1]);//交换 
        				swap(id[j], id[j+1]);//交换 
        			}
        		}
        	}
        	cout << id[k-1] << " " << score[k-1];
        	return 0;
        }
        
        • 0
          @ 2023-12-23 21:14:22
          #include<bits/stdc++.h>
          using namespace std;
          int n,k;
          struct exam{
          	long long no;
          	double sc;
          }s[105];
          bool a(exam x,exam y){
          	return x.sc>=y.sc;
          }
          int main(){
          	cin>>n>>k;
          	for(int i=0;i<n;i++) cin>>s[i].no>>s[i].sc;
          	sort(s,s+n,a);
          	cout<<s[k-1].no<<" "<<s[k-1].sc;
          	return 0;
          }
          
          • -1
            @ 2024-11-22 18:58:12
            //结构体版
            #include <bits/stdc++.h>
            using namespace std;
            int n, k;
            struct{
            	
            	int id;//名字 
            	double score;//分数 
            }stu[111];
            
            int main()
            {
            	cin >> n >> k;
            	for(int i = 0; i < n; i++)
            	{
            		cin >> stu[i].id >> stu[i].score;
            	}
            	for(int i = 0; i < n; i++)
            	{
            		for(int j = 0; j < n-i-1; j++)//n-i-1,只和前面的比 
            		{
            			if(stu[j].score < stu[j+1].score)//成绩更高 
            			{
            				swap(stu[j].score, stu[j+1].score);//交换 
            				swap(stu[j].id, stu[j+1].id);//交换 
            			}
            		}
            	}
            	cout << stu[k-1].id << " " << stu[k-1].score;
            	return 0;
            }
            
            • -4
              @ 2024-8-26 17:53:33
              #include<iostream>
              using namespace std;
              int n,k;
              struct student {//定义结构体 
              	int num;//学号 
              	float score;//分数 
              }a[101];//开数组 
              int main() {
              	cin>>n>>k;
              	for(int i=0;i<n;i++) 
              	cin>>a[i].num>>a[i].score;
              	for(int i=0;i<n;i++) {//冒泡排序 
              		for(int i=0;i<n-1;i++)
              		if(a[i].score<a[i+1].score)
              		swap(a[i],a[i+1]);
              	}
              	cout<<a[k-1].num<<' '<<a[k-1].score;//注意要减1(数组从0开始) 
              	return 0;//OK! 
              }
              
              • 1

              Information

              ID
              662
              Time
              1000ms
              Memory
              256MiB
              Difficulty
              6
              Tags
              # Submissions
              160
              Accepted
              49
              Uploaded By