royalsflush

Magic Trick - Live Archive 3154 AC

Sep 7th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. char val[] = {'1','2','3','4','5',
  7.     '6','7','8','9','T','J','Q','K'};
  8. char suit[] = {'H', 'C', 'D', 'S'};
  9.  
  10. struct card {
  11.     int v,s;
  12.  
  13.     bool operator==(card& a) {
  14.         return this->s==a.s && this->v==a.v;
  15.     }
  16. };
  17.  
  18. int t;
  19. card cs[4];
  20.  
  21. void read(card& a) {
  22.     char tmp[5];
  23.     scanf(" %s", tmp);
  24.  
  25.     for (int i=0; i<13; i++)
  26.         if (tmp[0]==val[i])
  27.             a.v=i;
  28.    
  29.     for (int i=0; i<4; i++)
  30.         if (tmp[1]==suit[i])
  31.             a.s=i;
  32. }
  33.  
  34. bool cmp(card a, card b) {
  35.     if (a.s==b.s)
  36.         return a.v<b.v;
  37.     return a.s<b.s;
  38. }
  39.  
  40. int compare() {
  41.     card ord[3];
  42.     int p[3] = {0,1,2};
  43.     int cnt=1;
  44.  
  45.     for (int i=0; i<3; i++)
  46.         ord[i]=cs[i+1];
  47.  
  48.     sort(ord,ord+3,cmp);
  49.  
  50.     do {
  51.         if (cs[1]==ord[p[0]] &&
  52.             cs[2]==ord[p[1]] &&
  53.             cs[3]==ord[p[2]])
  54.         return cnt;
  55.         cnt++;
  56.     } while (next_permutation(p,p+3));
  57.  
  58.     return cnt;
  59. }
  60.  
  61. int main() {
  62.     scanf("%d", &t);
  63.  
  64.     while (t--) {
  65.         for (int i=0; i<4; i++)
  66.             read(cs[i]);
  67.        
  68.         int vC = (cs[0].v+compare())%13;
  69.         printf("%c%c\n", val[vC],suit[cs[0].s]);
  70.     }
  71.     return 0;
  72. }
Add Comment
Please, Sign In to add comment