View Code of Problem 100

import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()) {
			int n =in.nextInt();
			if(n==0) {
				break;
			}
			in.nextLine();
			String [][] song = new String[n][3];
			for(int i =0;i<n;i++) {
				String[] message = in.nextLine().split(" ");
				song[i][0]=message[0];
				String[] time = message[1].split(":");
				int minute = Integer.parseInt(time[0]);
				int second = Integer.parseInt(time[1]);
				song[i][1] = String.valueOf(minute*60+second);
				song[i][2]="0";
			}
			int m =in.nextInt();
			in.nextLine();
			for(int i =0;i<m;i++) {
				String[] message = in.nextLine().split(" ");
				String name = message[0];
				String[] time = message[1].split(":");
				int minute = Integer.parseInt(time[0]);
				int second = Integer.parseInt(time[1]);
				int t =minute*60+second;
				for(String[] s:song) {
					if(s[0].equals(name)) {
						s[2]=String.valueOf(Integer.parseInt(s[2])+5*t/Integer.parseInt(s[1]));
					}
				}
			}
			for(int i =0;i<n-1;i++) {
				for(int j =0;j<n-1-i;j++) {
					if(Integer.parseInt(song[j][2])<Integer.parseInt(song[j+1][2])) {
						String[] temp = song[j];
						song[j]=song[j+1];
						song[j+1]=temp;
					}else if(Integer.parseInt(song[j][2])==Integer.parseInt(song[j+1][2])){
						if(song[j][0].compareTo(song[j+1][0])>0) {
							String[] temp = song[j];
							song[j]=song[j+1];
							song[j+1]=temp;
						}
					}
				}
			}
			for(String[] a:song) {				
				System.out.println(a[0]+" "+a[2]);
			}
		}		
	}
}

Double click to view unformatted code.


Back to problem 100