fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <string>
  4. #include <stdlib.h> //atoi
  5.  
  6. using namespace std;
  7.  
  8. int findVal(const string card) {
  9. int rank = atoi(&card[0]);
  10. return rank == 0 ? 10 : rank;
  11. }
  12.  
  13. int main()
  14. {
  15. int testCases;
  16. cin >> testCases;
  17.  
  18. for (int t = 1; t <= testCases; t++) {
  19. array<string, 52> pile;
  20.  
  21. for (auto &card : pile) cin >> card;
  22.  
  23. int topPile = 26, Y = 0;
  24. for (int i = 0; i < 3; i++) {
  25. int X = findVal(pile[topPile]);
  26. Y += X;
  27.  
  28. // Put this card and the top (10-X) cards of the pile away
  29. topPile -= ((10 - X) + 1);
  30. }
  31.  
  32. // we don't have to place all 25 cards back; just the ones to get Y-th:
  33. int stop = 26 + (Y - topPile);
  34. for (int i = 27; i < stop; i++) pile[++topPile] = pile[i];
  35.  
  36. // Y starts from 0 here, so the Y-th card is in the idx Y-1
  37. cout << "Case " << t << ": " << pile[Y-1] << endl;
  38. }
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 4368KB
stdin
2
AC KC QC JC TC 9C 8C 7C 6C 5C 4C 3C 2C AD KD QD JD TD 9D 8D 7D 6D 5D 4D 3D 2D 3S KH
QH JH TH 9H 8H 7H 6H 5H 4H 3H 2H AS KS QS JS TS 9S 8S 7S 6S 5S 4S AH 2S
AC KC QC JC TC 9C 8C 7C 6C 5C 4C 3C 2C AD KH QH JH TH 9H 8H 7H 6H 5H 4H 3H 2H AS
KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S KD QD JD TD 9D 8D 7D 6D 5D 4D 3D 2D AH
stdout
Case 1: 8H
Case 2: 8S