Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <queue>
  3. using namespace std;
  4. int trans(char c) {
  5. if(c >= '0' && c <= '9')
  6. return c-'0';
  7. if(c == 'A') return 1;
  8. if(c == 'T') return 10;
  9. if(c == 'J') return 11;
  10. if(c == 'Q') return 12;
  11. if(c == 'K') return 13;
  12. }
  13. int main() {
  14. // freopen("input.txt", "r", stdin);
  15. // freopen("output2.txt", "w", stdout);
  16. char s[50];
  17. int card[52];
  18. int i;
  19. while(true) {
  20. for(i = 0; i < 52; i++) {
  21. scanf("%s", s);
  22. if(s[0] == '#') return 0;
  23. card[i] = trans(s[1]);
  24. }
  25. queue<int> A, B;
  26. for(i = 51; i >= 0; i--) {
  27. if(i%2) A.push(card[i]);
  28. else B.push(card[i]);
  29. }
  30. int turn = 1;//0 A, 1 B
  31. int judge = -1;
  32. queue<int> H;//heap
  33. while(true) {
  34. if(turn == 0 && A.empty()) {
  35. judge = 0;
  36. break;
  37. }
  38. if(turn == 1 && B.empty()) {
  39. judge = 1;
  40. break;
  41. }
  42. int CARD;
  43. if(turn == 0)
  44. CARD = A.front(), A.pop();
  45. else
  46. CARD = B.front(), B.pop();
  47. //printf("%d - %c %d %d\n", CARD, turn+'A', A.size(), B.size());
  48. H.push(CARD);
  49. turn = 1-turn;
  50. int ended = 1;
  51. while(CARD >= 11 || CARD == 1) {
  52. ended = 0;
  53. int paid;
  54. if(CARD == 1) paid = 4;
  55. else if(CARD == 11) paid = 1;
  56. else if(CARD == 12) paid = 2;
  57. else if(CARD == 13) paid = 3;
  58. for(i = 0; i < paid; i++) {
  59. if(turn == 0 && A.empty()) {
  60. judge = 0;
  61. break;
  62. }
  63. if(turn == 1 && B.empty()) {
  64. judge = 1;
  65. break;
  66. }
  67. if(turn == 0)
  68. CARD = A.front(), A.pop();
  69. else
  70. CARD = B.front(), B.pop();
  71. H.push(CARD);
  72. //printf("%d - %c\n", CARD, turn+'A');
  73. if(CARD == 1 || CARD >= 11)//change
  74. break;
  75. }
  76. if(judge >= 0) break;
  77. turn = 1-turn;
  78. }
  79. if(judge >= 0) break;
  80. if(ended == 0) {
  81. if(turn == 0) {
  82. while(!H.empty()) {
  83. A.push(H.front());
  84. H.pop();
  85. }
  86. } else {
  87. while(!H.empty()) {
  88. B.push(H.front());
  89. H.pop();
  90. }
  91. }
  92. }
  93. }
  94. printf("%d%3d\n", 2-judge, judge ? A.size() : B.size());
  95. }
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement