Created
April 27, 2015 05:02
Revisions
-
rogerioagjr created this gist
Apr 27, 2015 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ import java.io.*; import java.util.Arrays; public class solucao { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int num,qtd,i,j,x,y; String[] aux; aux = in.readLine().split(" "); num = Integer.parseInt(aux[0]); qtd = Integer.parseInt(aux[1]); String[] n = new String[num]; String[] t = new String[qtd]; int[] h = new int[num]; for(i = 0; i < qtd; i++)t[i] = ""; for(i = 0; i < num; i++){ aux = in.readLine().split(" "); n[i] = aux[0]; h[i] = Integer.parseInt(aux[1]); } for(i = 0; i < num - 1; i++){ for(j = i+1; j < num; j++){ if(h[i] > h[j]){ x = h[i]; h[i] = h[j]; h[j] = x; aux[0] = n[i]; n[i] = n[j]; n[j] = aux[0]; } } } j = 0; for(i = num - 1; i > -1; i--){ t[j] += n[i] + " "; j++; if(j == qtd)j = 0; } for(i = 0; i < qtd; i++){ out.write("Time "+(i+1)+"\n"); y = 0; x = 0; for(j = 0; j < t[i].length(); j++){ if(t[i].charAt(j) == ' '){ n[y] = t[i].substring(x,j); y++; x = j+1; } } Arrays.sort(n,0,y); for(j = 0; j < y; j++){ out.write(n[j]+"\n"); } out.write("\n"); } out.flush(); } }