Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- LinkedHashMap<String, HashSet<String>> player = new LinkedHashMap<>();
- String line = scan.nextLine();
- while (!line.equals("JOKER")){
- String[] tokens = line.split(": +");
- String name = tokens[0];
- HashSet<String> cards = Arrays.stream(tokens[1].split(", +"))
- .collect(Collectors.toCollection(HashSet::new));
- if (!player.containsKey(name)){
- player.put(name, cards);
- }else {
- player.get(name).addAll(cards);
- }
- line= scan.nextLine();
- }
- for (String str : player.keySet()) {
- int sum= CalculateSum(player.get(str));
- System.out.println(str+ ": "+ sum);
- }
- }
- private static int CalculateSum(HashSet<String> strings) {
- int sum=0;
- for (String string : strings) {
- int temp=0;
- switch (string.charAt(0)){
- case '2':
- temp=2;
- break;
- case '3':
- temp=3;
- break;
- case '4':
- temp=4;
- break;
- case '5':
- temp=5;
- break;
- case '6':
- temp=6;
- break;
- case '7':
- temp=7;
- break;
- case '8':
- temp=8;
- break;
- case '9':
- temp=9;
- break;
- case '1':
- temp=10;
- break;
- case 'J':
- temp=11;
- break;
- case 'Q':
- temp=12;
- break;
- case 'K':
- temp=13;
- break;
- case 'A':
- temp=14;
- break;
- }
- switch (string.charAt(string.length()-1)){
- case 'S':
- temp*=4;
- break;
- case 'H':
- temp*=3;
- break;
- case 'D':
- temp*=2;
- break;
- }
- sum+=temp;
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement