Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <set>
- int main()
- {
- std::multimap<int, int> m;
- int count = 0;
- int key = 0;
- while (count != 5)
- {
- std::cout << "Enter a valid number: [1-6]" << std::endl;
- std::cin >> key;
- while (key < 0 || key > 6)
- {
- std::cout << "Your input doesn't count! Enter a valid number: [1-6]" << std::endl;
- std::cin >> key;
- }
- m.insert({ key, count });
- ++count;
- }
- std::multiset<int> s;
- for (auto it : m)
- {
- s.insert(it.first);
- }
- for (auto it = s.begin(); it != s.end(); ++it)
- {
- if (s.count(*it) == 5)
- {
- std::cout << "yahtzee";
- break;
- }
- if (s.count(*it) == 4 || (s.count(*it + 1) == 4) || (s.count(*it + 2) == 4)
- || (s.count(*it + 3) == 4) || (s.count(*it + 4) == 4) || (s.count(*it + 5) == 4))
- {
- std::cout << "Four of a kind!";
- break;
- }
- if (s.count(*it) == 3 || (s.count(*it + 1) == 3) || (s.count(*it + 2) == 3)
- || (s.count(*it + 3) == 3) || (s.count(*it + 4) == 3) || (s.count(*it + 5) == 3))
- {
- s.erase(*it);
- auto i = s.begin();
- if ((s.count(*i)) == 2 || (s.count(*i)) == 3)
- {
- std::cout << "full house!";
- break;
- }
- else
- {
- std::cout << "Three of a kind!";
- break;
- }
- }
- if (*it == (*it + 1) - 1 && ((s.count(*it) == 2) || (s.count(*it+1) == 2
- || (s.count(*it+2) == 2) || (s.count(*it+3) == 2) || (s.count(*it+4) == 2) || (s.count(*it + 5) == 2))))
- {
- std::cout << "Small straight!";
- break;
- }
- if (*it == (*it + 1) - 1 && (s.count(*it) != 2) && (s.count(*it + 1) != 2)
- && (s.count(*it + 2) != 2) && (s.count(*it +3) != 2) && (s.count(*it + 4) != 2) && (s.count(*it + 5) != 2))
- {
- std::cout << "Large straight!";
- break;
- }
- std::cout << "Nothing" << std::endl;
- break;
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement