Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class _08_HandsOfCards {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Map<String, Set<String>> game = new LinkedHashMap<>();
- String txt = "";
- while (!"JOKER".equals(txt = sc.nextLine())) {
- String[] data = txt.split(": ");
- String name = data[0];
- game.putIfAbsent(name, new HashSet<>());
- Set<String> deck = game.get(name);
- String[] c = (data[1].split(", "));
- deck.addAll(Arrays.asList(c));
- }
- for (Map.Entry<String, Set<String>> entry : game.entrySet()) {
- int sum = 0;
- for (String card : entry.getValue()) {
- String power = card.substring(0, card.length() - 1);
- String type = card.substring(card.length() - 1);
- int powerValue = 0;
- int typeValue = 0;
- switch (type) {
- case "C":
- typeValue = 1;
- break;
- case "D":
- typeValue = 2;
- break;
- case "H":
- typeValue = 3;
- break;
- case "S":
- typeValue = 4;
- break;
- }
- switch (power) {
- case "J":
- powerValue = 11;
- break;
- case "Q":
- powerValue = 12;
- break;
- case "K":
- powerValue = 13;
- break;
- case "A":
- powerValue = 14;
- break;
- default:
- powerValue = Integer.parseInt(power);
- }
- sum += typeValue * powerValue;
- }
- System.out.println(String.format("%s: %d", entry.getKey(), sum));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement