Who took the kth exam

In an exam, each student's grades are different. Now, knowing the student number and grade of each student, find the student number and grade of the kth student.
enter

The first line has two integers, which are the number of students n (1≤n≤100), and the k (1≤k≤n) for the kth student.

Then there are n lines of data, each line includes a student number (integer) and a grade (floating point number), separated by a space.
Output
Output the student number and grade of the kth student, separated by spaces. (Note: C, C++, please use %g to output grades)
Sample input
5 3
90788001 67.8
90788002 90.3
90788003 61
90788004 68.4
90788005 73.9

Sample output
90788004 68.4

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        int n,k,s;
        int sno[]=new int[101];
        double grade[]=new double[101];
        double g;
        Scanner scan=new Scanner(System.in);
        n=scan.nextInt();
        k=scan.nextInt();
        for(int i=0;i<n;i++)
        {
            sno[i]=scan.nextInt();
            grade[i]=scan.nextDouble();
        }
        for(int i=0;i<n-1;i++)
        {
            for(int j=0;j<n-i-1;j++)
            {
                if(grade[j]<grade[j+1])
                {
                    g=grade[j];
                    grade[j]=grade[j+1];
                    grade[j+1]=g;
                    s=sno[j];
                    sno[j]=sno[j+1];
                    sno[j+1]=s;
                }
            }

        }
        System.out.println(sno[k-1]+" "+grade[k-1]);
    }

}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326616229&siteId=291194637