Advertisement
deyanmalinov

08. Hands Of Cards

Apr 2nd, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.62 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         LinkedHashMap<String, HashSet<String>> player = new LinkedHashMap<>();
  8.         String line = scan.nextLine();
  9.         while (!line.equals("JOKER")){
  10.             String[] tokens = line.split(": +");
  11.             String name = tokens[0];
  12.             HashSet<String> cards = Arrays.stream(tokens[1].split(", +"))
  13.                     .collect(Collectors.toCollection(HashSet::new));
  14.             if (!player.containsKey(name)){
  15.                 player.put(name, cards);
  16.             }else {
  17.                 player.get(name).addAll(cards);
  18.             }
  19.                    
  20.            
  21.             line= scan.nextLine();
  22.         }
  23.         for (String str : player.keySet()) {
  24.             int sum= CalculateSum(player.get(str));
  25.             System.out.println(str+ ": "+ sum);
  26.         }
  27.     }
  28.  
  29.     private static int CalculateSum(HashSet<String> strings) {
  30.        int sum=0;
  31.         for (String string : strings) {
  32.             int temp=0;
  33.             switch (string.charAt(0)){
  34.                 case '2':
  35.                     temp=2;
  36.                     break;
  37.                 case '3':
  38.                     temp=3;
  39.                     break;
  40.                 case '4':
  41.                     temp=4;
  42.                     break;
  43.                 case '5':
  44.                     temp=5;
  45.                     break;
  46.                 case '6':
  47.                     temp=6;
  48.                     break;
  49.                 case '7':
  50.                     temp=7;
  51.                     break;
  52.                 case '8':
  53.                     temp=8;
  54.                     break;
  55.                 case '9':
  56.                     temp=9;
  57.                     break;
  58.                 case '1':
  59.                     temp=10;
  60.                     break;
  61.                 case 'J':
  62.                     temp=11;
  63.                     break;
  64.                 case 'Q':
  65.                     temp=12;
  66.                     break;
  67.                 case 'K':
  68.                     temp=13;
  69.                     break;
  70.                 case 'A':
  71.                     temp=14;
  72.                     break;
  73.             }
  74.             switch (string.charAt(string.length()-1)){
  75.                 case 'S':
  76.                     temp*=4;
  77.                     break;
  78.                 case 'H':
  79.                     temp*=3;
  80.                     break;
  81.                 case 'D':
  82.                     temp*=2;
  83.                     break;
  84.             }
  85.             sum+=temp;
  86.         }
  87.  
  88.         return sum;
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement