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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| const int CardTypeCount = 13; enum CardType { Single, Double, Triple, TripleSingle, TripleDouble, Straight, DoubleStraight, TripleStraight, PlaneWithSingle, PlaneWithDouble, Bomb, SuperBomb, BombDouble, }; std::map<std::multiset<int>, CardType> CardTypeMap{ {std::multiset<int>({4}),CardType::Bomb}, {std::multiset<int>({4,2}),CardType::BombDouble},
{std::multiset<int>({3}),CardType::Triple}, {std::multiset<int>({3,1}),CardType::TripleSingle}, {std::multiset<int>({3,2}),CardType::TripleDouble},
{std::multiset<int>({3,3}),CardType::TripleStraight}, {std::multiset<int>({3,3,3}),CardType::TripleStraight}, {std::multiset<int>({3,3,3,3}),CardType::TripleStraight}, {std::multiset<int>({3,3,3,3,3}),CardType::TripleStraight},
{std::multiset<int>({3,3,1,1}),CardType::PlaneWithSingle}, {std::multiset<int>({3,3,3,1,1,1}),CardType::PlaneWithSingle},
{std::multiset<int>({3,3,2,2}),CardType::PlaneWithDouble}, {std::multiset<int>({3,3,3,2,2,2}),CardType::PlaneWithDouble},
{std::multiset<int>({2}),CardType::Double},
{std::multiset<int>({2,2,2}),CardType::DoubleStraight}, {std::multiset<int>({2,2,2,2}),CardType::DoubleStraight}, {std::multiset<int>({2,2,2,2,2}),CardType::DoubleStraight}, {std::multiset<int>({2,2,2,2,2,2}),CardType::DoubleStraight}, {std::multiset<int>({2,2,2,2,2,2,2}),CardType::DoubleStraight}, {std::multiset<int>({2,2,2,2,2,2,2,2}),CardType::DoubleStraight},
{std::multiset<int>({1}),CardType::Single}, {std::multiset<int>({1,1}),CardType::Double},
{std::multiset<int>({1,1,1,1,1}),CardType::Straight}, {std::multiset<int>({1,1,1,1,1,1}),CardType::Straight}, {std::multiset<int>({1,1,1,1,1,1,1}),CardType::Straight}, {std::multiset<int>({1,1,1,1,1,1,1,1}),CardType::Straight}, {std::multiset<int>({1,1,1,1,1,1,1,1,1}),CardType::Straight}, {std::multiset<int>({1,1,1,1,1,1,1,1,1,1}),CardType::Straight}, {std::multiset<int>({1,1,1,1,1,1,1,1,1,1,1}),CardType::Straight}, {std::multiset<int>({1,1,1,1,1,1,1,1,1,1,1,1}),CardType::Straight}, {std::multiset<int>({1,1,1,1,1,1,1,1,1,1,1,1,1}),CardType::Straight}, }; class CardToken { private: std::string BaseString; CardType Type; template<class T> std::multiset<std::pair<int, T>> Count(std::vector<T> v) { constexpr int tmpsize = std::numeric_limits<T>::max() - std::numeric_limits<T>::min(); int tmp[tmpsize]; memset(tmp, 0, sizeof(tmp)); for (int i = 0; i < v.size(); i++) { tmp[v[i]]++; } std::multiset<pair<int, T>> ans; for (int i = 0; i < tmpsize; i++) { if (tmp[i] != 0) { ans.insert(pair<int, T>(tmp[i], i)); } } return ans; } template<class T> CardType GetCardTypeByCountResult(std::multiset<std::pair<int, T>> CountResult) { std::multiset<int> times, cards; for (typename std::multiset<std::pair<int, T>>::const_iterator iter = CountResult.begin(); iter != CountResult.end(); iter++) { times.insert(iter->first); cards.insert(iter->second); } CardType ans = CardTypeMap[times]; if (ans == CardType::Double && cards.count('S') && cards.count('L')) { ans = CardType::SuperBomb; } return ans; } public: CardToken(std::string BaseString) :BaseString(BaseString) {}; CardToken() { BaseString = ""; }
CardType GetCardType()const { return Type; } void SetCardType(CardType Type) { if (Type >= CardTypeCount || Type < 0) { throw "CardType undefined!"; } this->Type = Type; } std::string GetBaseString()const { return BaseString; } void SetBaseString(const std::string& BaseString) { this->BaseString = BaseString; this->Type = GetCardTypeByCountResult(Count(std::vector<char>(BaseString.begin(), BaseString.end()))); } };
|