HDOJ--1718 Rank(水题用了点小技巧)

来源:互联网 发布:淘宝 不经过物流 收货 编辑:程序博客网 时间:2024/06/06 19:30
Problem Description
Jackson wants to know his rank in the class. The professor has posted a list of student numbers and marks. Compute Jackson’s rank in class; that is, if he has the top mark(or is tied for the top mark) his rank is 1; if he has the second best mark(or is tied) his rank is 2, and so on.
 
Input
The input consist of several test cases. Each case begins with the student number of Jackson, an integer between 10000000 and 99999999. Following the student number are several lines, each containing a student number between 10000000 and 99999999 and a mark between 0 and 100. A line with a student number and mark of 0 terminates each test case. There are no more than 1000 students in the class, and each has a unique student number.
 
Output
For each test case, output a line giving Jackson’s rank in the class.
 
Sample Input
2007010120070102 10020070101 3320070103 2220070106 330 0
 

Sample Output
2
 
设计思路:就是输入一个学号,(我这没有用字符串来做而是直接来一个数组了)然后在输入一堆学号和成绩,然后输出这个学号所对应的成绩排名。~~~第一次采用for死循环来输入数组数据,并且用if判断数组的有效数据
附代码如下:import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc =new Scanner(System.in);while(sc.hasNext()){long arr[]=new long[1005];long brr[]=new long[1005];long n=sc.nextLong();int conut=0;int m=0;for(int i=0;;i++){//死循环输入数据arr[i]=sc.nextLong();brr[i]=sc.nextLong();if(arr[i]==0){//学号为0则表明数组为初始值了,即前面的数据有效conut=i;//记录最大的数组下标break;//并且退出循环}if(arr[i]==n){m=i;//记录输入的学号位置}}int temp=1;//名次数,故让它所有的成绩,超过一个人加一 ,直到与所有的成绩比较完for(int i=0;i<conut;i++){if(brr[i]>brr[m]){temp++;}}System.out.println(temp);}}}

0 0