View Code of Problem 100

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()) {
			int n = scanner.nextInt();
			if(n == 0) {
				break;
			}
			Map<String,Music> map = new HashMap<String,Music>();
			for(int i=0; i<n; i++) {
				String name = scanner.next();
				String[] time = scanner.next().split(":");
				map.put(name,new Music(name, Integer.valueOf(time[0]) * 60 + Integer.valueOf(time[1])));
			}
			
			int m = scanner.nextInt();
			for(int i=0; i<m; i++) {
				Music mu = map.get(scanner.next());
				String[] time = scanner.next().split(":");
				mu.setUseTime(Integer.valueOf(time[0]) * 60 + Integer.valueOf(time[1]) );
			}
			

			List<Map.Entry<String, Music>> list = new ArrayList<Map.Entry<String,Music>>(map.entrySet());
			Collections.sort(list,new Comparator<Map.Entry<String, Music>>() {

				@Override
				public int compare(Entry<String, Music> o1, Entry<String, Music> o2) {
				
					int k =  o2.getValue().getScore() - o1.getValue().getScore();
					if(k == 0) {
						return o1.getKey().compareTo(o2.getKey());
					}
					return k;
				}
			});
			
			for(Map.Entry<String, Music> maEntry : list) {
				System.out.println(maEntry.getKey()+" "+maEntry.getValue().getScore());
			}
			
		}
	}

	
}
class Music {
	String name;
	int time;
	int useTime;
	int score;
	public Music(String name, int time) {
		super();
		this.name = name;
		this.time = time;
	}
	public int getUseTime() {
		return useTime;
	}
	public void setUseTime(int useTime) {
		this.useTime = useTime;	
		this .score = fenshu(this.useTime, this.time) + this.getScore();
	}
	
	public int fenshu(int useTime2, int time2) {
		// TODO Auto-generated method stub
		double index = useTime*1.0 /time;
		if(index >= 0 && index < 0.2) {
			return 0;
		}else if(index>= 0.2 && index < 0.4) {
			return 1;
		}else if(index >= 0.4 && index < 0.6 ) {
			return 2;
		}else if(index>= 0.6 && index < 0.8) {
			return 3;
		}else if(index >= 0.8 && index < 1) {
			return 4;
		}else {
			return 5;
		}

	}
	public int getScore() {
		return score;
	}
	
}

Double click to view unformatted code.


Back to problem 100