#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 64;
map<string, int> mj = {
{"1T",1},{"2T",2},{"3T",3},{"4T",4},{"5T",5},{"6T",6},{"7T",7},{"8T",8},{"9T",9},
{"1S",11},{"2S",12},{"3S",13},{"4S",14},{"5S",15},{"6S",16},{"7S",17},{"8S",18},{"9S",19},
{"1W",21},{"2W",22},{"3W",23},{"4W",24},{"5W",25},{"6W",26},{"7W",27},{"8W",28},{"9W",29},
{"DONG",31},{"NAN",32},{"XI",34},{"BEI",35},{"ZHONG",37},{"FA",38},{"BAI",40}
};
vector<string> mj2(64);
int cnt[maxn],input[maxn],n;
bool search(int d) {
if (d == 4) return true;
for (int i = 0; i < 41; i++) {
if (cnt[i] >= 3) {
cnt[i] -= 3;
if (search(d + 1)) return true;
cnt[i] += 3;
}
}
for (int i = 2; i < 41; i++) {
if (cnt[i] > 0 && cnt[i - 1] > 0 && cnt[i - 2] > 0) {
cnt[i - 2]--;
cnt[i - 1]--;
cnt[i]--;
if (search(d + 1)) return true;
cnt[i - 2]++;
cnt[i - 1]++;
cnt[i]++;
}
}
return false;
}
bool check() {
for (int i = 0; i < 41; i++) {
if (cnt[i] >= 2) {
cnt[i] -= 2;
if (search(0)) return true;
cnt[i] += 2;
}
}
return false;
}
int main()
{
string name;
int kCase = 0;
for (auto it = mj.begin(); it != mj.end(); it++) {
mj2[it->second] = it->first;
}
while (cin >> name && name != "0") {
input[0] = mj[name];
for (int i = 1; i < 13; i++) {
cin >> name;
input[i] = mj[name];
}
bool ok = false;
cout << "Case " << ++kCase << ":";
for (int j = 1; j < 41;j++) {
if (mj2[j].empty())continue;
memset(cnt, 0, sizeof(cnt));
int cur = j;
for (int i = 0; i < 13; i++)cnt[input[i]]++;
if (cnt[cur] >= 4) continue;
cnt[cur] ++;
if (check()) {
ok = true;
cout << " " << mj2[cur];
}
cnt[cur]--;
}
if (!ok) cout << " Not ready";
cout << endl;
}
return 0;
}
08-29
744