// @BEGIN_OF_SOURCE_CODE /* @JUDGE_ID: 17243NT 181 C++ */ // Send to judge@uva.es #include #include #include #ifdef ONLINE_JUDGE #define ins cin #define outs cout #else #define ins fin #define outs fout ifstream fin("myprog.in"); ofstream fout("myprog.out"); #endif typedef struct { int r; char s; } cards; #define swap(a,b) {cards t = a; a = b; b = t;} bool islessleader(cards a, cards b); bool islessfollow(cards a, cards b, char csuit); bool islessjudge(cards a, cards b, char csuit); void trick(int leader); cards playleader(int p); cards playfollow(int p, char csuit); cards deck[52]; cards hands[5][10]; char trump; int score[5]; int ncards; int main() { char c, d; int i; while(ins >> c) { if(c == '#') break; ins.putback(c); ncards = 10; for(i = 0; i < 5; i++) score[i] = 0; for(i = 0; i < 52; i++) { ins >> c >> d; if(c == 'T') deck[i].r = 10; else if(c == 'J') deck[i].r = 11; else if(c == 'Q') deck[i].r = 12; else if(c == 'K') deck[i].r = 13; else if(c == 'A') deck[i].r = 14; else deck[i].r = c - '0'; deck[i].s = d; } for(i = 0; i < 10; i++) { hands[0][i] = deck[i * 5]; hands[1][i] = deck[i * 5 + 1]; hands[2][i] = deck[i * 5 + 2]; hands[3][i] = deck[i * 5 + 3]; hands[4][i] = deck[i * 5 + 4]; } if(deck[50].r < deck[51].r) { trump = deck[51].s; } else if(deck[50].r > deck[51].r) { trump = deck[50].s; } else if(deck[50].s < deck[51].s) { trump = deck[51].s; } else { trump = deck[50].s; } trick(0); outs << setw(3) << score[4] << setw(3) << score[0] << setw(3) << score[1] << setw(3) << score[2] << setw(3) << score[3] << endl; } return 0; } void trick(int leader) { char csuit; int i, l; cards toplay[5]; if(ncards <= 0) return; toplay[leader] = playleader(leader); csuit = toplay[leader].s; for(i = 1; i < 5; i++) toplay[(leader + i) % 5] = playfollow((leader + i) % 5, csuit); l = 0; for(i = 1; i < 5; i++) if(islessjudge(toplay[l], toplay[i], csuit)) l = i; for(i = 0; i < 5; i++) if(toplay[i].s == 'H') score[l] += toplay[i].r; ncards--; trick(l); } cards playleader(int p) { int best = 0; int i; for(i = 1; i < ncards; i++) if(islessleader(hands[p][best], hands[p][i])) best = i; swap(hands[p][best], hands[p][ncards - 1]); return hands[p][ncards - 1]; } cards playfollow(int p, char csuit) { int best = 0; int i; for(i = 1; i < ncards; i++) if(islessfollow(hands[p][best], hands[p][i], csuit)) best = i; swap(hands[p][best], hands[p][ncards - 1]); return hands[p][ncards - 1]; } bool islessfollow(cards a, cards b, char csuit) { if(b.s == csuit) if(a.s != csuit) return true; else return (a.r < b.r); if(a.s == csuit) return false; if(b.s == trump) if(a.s != trump) return true; else return (a.r < b.r); if(a.s == trump) return false; if(a.r < b.r) return true; if(a.r > b.r) return false; return (a.s < b.s); } bool islessleader(cards a, cards b) { if(a.r < b.r) return true; if(a.r > b.r) return false; if(b.s == trump) return true; if(a.s == trump) return false; return (a.s < b.s); } bool islessjudge(cards a, cards b, char csuit) { if(b.s == trump) if(a.s != trump) return true; else return (a.r < b.r); if(a.s == trump) return false; if(b.s == csuit) if(a.s != csuit) return true; else return (a.r < b.r); if(a.s == csuit) return false; if(a.r < b.r) return true; if(a.r > b.r) return false; return (a.s < b.s); } // @END_OF_SOURCE_CODE