o_ignatov

Problem 1 - HandScore

Oct 15th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.*;
  5.  
  6. public class HandScore {
  7. public static void main(String[] args) throws IOException {
  8. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  9. String[] input = reader.readLine().split("\\s+");
  10. Deque<String> cards = new ArrayDeque<>();
  11. cards.addAll(Arrays.asList(input));
  12. int sum = 0;
  13. while (!cards.isEmpty()){
  14. String element = cards.pop();
  15. int seqSum = getCardPower(element);
  16. int count = 1;
  17. while (cards.peek()!= null && cards.peek().substring(cards.peek().length()-1).equals(element.substring(element.length()-1))){
  18. count++;
  19. seqSum += getCardPower(cards.pop());
  20. }
  21. sum += seqSum * count;
  22. }
  23. System.out.println(sum);
  24. }
  25. private static int getCardPower(String card){
  26. List<String> powers = Arrays.asList("","","2","3","4","5","6","7","8","9","10","","J","Q","K","A");
  27. return powers.indexOf(card.substring(0,card.length()-1));
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment