Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <unordered_set>
- int SuitToNum(char suit) {
- if (suit == 'S') return 0;
- if (suit == 'C') return 1;
- if (suit == 'D') return 2;
- return 3;
- }
- char NumToSuit(int num) {
- if (num == 0) return 'S';
- if (num == 1) return 'C';
- if (num == 2) return 'D';
- return 'H';
- }
- int ValToNum(char val) {
- if (val <= '9' && val >= '2') {
- return val - '2';
- }
- if (val == 'T') return 8;
- if (val == 'J') return 9;
- if (val == 'Q') return 10;
- if (val == 'K') return 11;
- return 12;
- }
- std::string NumToVal(int num) {
- if (num >= 0 && num <= 7) return std::to_string(num + 2);
- if (num == 8) return "T";
- if (num == 9) return "J";
- if (num == 10) return "Q";
- if (num == 11) return "K";
- return "A";
- }
- std::pair<int, int> Input(std::vector<std::vector<bool>>& used,
- std::vector<std::pair<std::string, std::string>>& cards,
- int n) {
- std::string myFirstCard, mySecondCard;
- std::cin >> myFirstCard >> mySecondCard;
- used[SuitToNum(myFirstCard[1])][SuitToNum(myFirstCard[0])] = true;
- used[SuitToNum(mySecondCard[1])][SuitToNum(mySecondCard[0])] = true;
- cards[0] = {myFirstCard, mySecondCard};
- for (int i = 1; i < n; ++i) {
- std::string firstCard, secondCard;
- std::cin >> firstCard >> secondCard;
- used[SuitToNum(firstCard[1])][SuitToNum(firstCard[0])] = true;
- used[SuitToNum(secondCard[1])][SuitToNum(secondCard[0])] = true;
- cards[i] = {firstCard, secondCard};
- }
- return {ValToNum(myFirstCard[0]), ValToNum(mySecondCard[0])};
- }
- std::vector<std::string> SameCardsCase(std::vector<std::vector<bool>> used,
- std::vector<std::pair<std::string, std::string>>& cards,
- int val, int n) {
- std::vector<std::string> answer;
- std::vector<char> suits = {'S', 'C', 'D', 'H'};
- // set case
- for (char suit : suits) {
- if (!used[SuitToNum(suit)][val]) {
- std::string cval(NumToVal(val));
- cval += suit;
- answer.push_back(cval);
- }
- }
- // pair case
- bool isImpossible = false;
- std::vector<int> withSame; // кому нельзя дать сет
- for (int i = 1; i < n; ++i) {
- char val1 = cards[i].first[0];
- char val2 = cards[i].first[1];
- int numVal1 = ValToNum(val1);
- int numVal2 = ValToNum(val2);
- if (val1 == val2) { // нельзя, тк сет
- if (numVal1 > val) {
- isImpossible = true;
- break;
- }
- for (char suit : suits) {
- used[SuitToNum(suit)][val1] = true;
- }
- }
- int numValMax = std::max(numVal1, numVal2);
- if (numValMax > val) { // нельзя, тк будет пара сильнее моей
- for (char suit : suits) {
- used[SuitToNum(suit)][val] = true;
- }
- }
- }
- if (isImpossible) return answer;
- for (int i = 0; i < 4; ++i) {
- for (int j = 0; j < 13; ++j) {
- if (!used[i][j]) {
- std::string cval(NumToVal(j));
- cval += NumToSuit(i);
- answer.push_back(cval);
- }
- }
- }
- return answer;
- }
- int main() {
- int t;
- std::cin >> t;
- for (int iter = 0; iter < t; ++iter) {
- int n;
- std::cin >> n;
- std::vector<std::vector<bool>> used(4, std::vector<bool>(13));
- std::vector<std::pair<std::string, std::string>> cards(n);
- std::pair<int, int> myCards;
- myCards = Input(used, cards, n);
- if (myCards.first == myCards.second) { // 2 одинаковые
- auto answer = SameCardsCase(used, cards, myCards.first, n);
- std::cout << answer.size() << "\n";
- for (auto& el : answer) {
- std::cout << el << "\n";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement