Guest User

Untitled

a guest
Oct 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4. public static void main(String args[]) {
  5. Scanner sc = new Scanner(System.in);
  6.  
  7. int T = Integer.valueOf(sc.nextLine());
  8. sc.nextLine();
  9.  
  10. for (int t = 0; t < T; t++) {
  11. float total = 0.0f;
  12. HashMap<String, Integer> hm = new HashMap<String, Integer>();
  13. ArrayList<String> tree = new ArrayList<String>();
  14. String input;
  15.  
  16. while (sc.hasNext()) {
  17. input = sc.nextLine();
  18. if (input.length() == 0)
  19. break;
  20.  
  21. if (!hm.containsKey(input)) {
  22. hm.put(input, 1);
  23. tree.add(input);
  24. }
  25. else
  26. hm.put(input, hm.get(input) + 1);
  27.  
  28. total++;
  29. }
  30.  
  31. Collections.sort(tree);
  32.  
  33. for (String s: tree)
  34. System.out.printf("%s %.4f\n", s, (float)hm.get(s)/total * 100);
  35.  
  36. if (t != T - 1)
  37. System.out.println();
  38. }
  39. }
  40. }
Add Comment
Please, Sign In to add comment