1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #include <iostream> #include <vector> #include <list> #include <sstream> #include <algorithm> #include <map> using namespace std;
vector<vector<string >> MainData;
std::map<std::string, int> cardOrder = { {"3", 1}, {"4", 2}, {"5", 3}, {"6", 4}, {"7", 5}, {"8", 6}, {"9", 7}, {"10", 8}, {"J", 9}, {"Q", 10}, {"K", 11}, {"A", 12} };
bool isSort(const string &left, const string &right) { return cardOrder[right] - cardOrder[left] == 1; }
void getStraight(std::list<std::string> &data) { std::vector<std::string> result; for (auto it = data.begin(); it != data.end();) { if (result.empty()) { result.push_back(*it); it = data.erase(it); continue; } if (isSort(result.back(), *it)) { result.push_back(*it); it = data.erase(it); } else { it++; } } if (result.size() >= 5) { MainData.push_back(result); } }
template<typename T> void Print(const T &data) { for (const auto &i : data) { cout << i << " "; } cout << "\n"; }
int main() { std::string line; getline(cin, line); list<string> data; istringstream iss(line); string str; while (iss >> str) { if (str == "2") continue; data.push_back(str); }
if (data.size() < 5) { cout << "No" << "\n"; return 0; }
data.sort([](const auto &left, const auto &right) { return cardOrder[left] < cardOrder[right]; });
while (data.size() >= 5) { getStraight(data); }
if (MainData.empty()) { cout << "No\n"; return 0; }
sort(MainData.begin(), MainData.end()); for (const auto &d : MainData) { Print(d); }
return 0; }
|