Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ui uint8_t
- class Card {
- int numar; // nu stiu ce ce dar nu mergea cu uint8_t
- string stema;
- public:
- Card(ui nr, string stema) : numar(nr), stema(stema) {}
- friend ostream& operator<<(ostream& os, const Card& card) {
- os << card.numar << "," << card.stema;
- return os;
- }
- friend bool operator==(const Card& a, const Card& b) {
- return a.numar == b.numar && a.stema == b.stema;
- }
- // bool operator==(const Card& c) const {
- // return this->numar == c.numar && this->stema == c.stema;
- // }
- // pentru set, dar nu merge :/
- // struct HashFunction {
- // size_t operator()(const Card& c) const {
- // size_t xHash = std::hash<int>()(c.numar);
- // size_t yHash;
- // if (c.stema == "rosu") {
- // yHash = std::hash<int>()(1);
- // } else if (c.stema == "romb") {
- // yHash = std::hash<int>()(2);
- // } else if (c.stema == "negru") {
- // yHash = std::hash<int>()(3);
- // } else if (c.stema == "trefla") {
- // yHash = std::hash<int>()(4);
- // }
- // return xHash ^ yHash;
- // }
- // };
- };
- int main() {
- string subiect;
- ifstream fin("blackjack.in");
- // cout << "Subiect: ";
- fin >> subiect;
- if (subiect == "check_cards") {
- // nu se specifica numarul de carti in datele de itnrate asa ca sunt obligat sa folosesc un fisier
- string temp;
- int no_cards = 0;
- vector<Card> deck;
- while (fin >> temp) {
- if (no_cards > 52) {
- // chiar daca nu trebuie sa verific pentru ca 13 * 4 = 52 si verificam daca bagi aceleasi carti, adica nu exista 53 de carti, daca exista
- // ori s-au bagat duplicate ori carti care nu exista.
- cout << "Pachet masluit" << endl;
- return -1;
- }
- int card_num = stoi(temp.substr(0, temp.find(",")));
- string card_stema = temp.substr(temp.find(",") + 1, temp.length());
- if (card_num < 2 || card_num > 14) {
- cout << "Pachet masluit" << endl;
- return -1;
- }
- if (card_stema == "romb" || card_stema == "rosu" || card_stema == "negru" || card_stema == "trefla") {
- // all good
- Card c(card_num, card_stema);
- if (find(deck.begin(), deck.end(), c) != deck.end()) {
- cout << "Pachet masluit" << endl;
- return -1;
- }
- deck.push_back(c);
- no_cards++;
- // cout << "Card number " << no_cards << ": " << c << endl;
- continue;
- } else {
- cout << "Pachet masluit" << endl;
- return -1;
- }
- }
- cout << "Pachet pentru Backjack" << endl;
- } else if (subiect == "shuffle_cards") { // imi asum ca deckul a fost verificat
- string temp;
- vector<Card> deck;
- int a1, x1, c1;
- int a2, x2, c2;
- cin >> a1 >> x1 >> c1 >> a2 >> x2 >> c2;
- while (fin >> temp) {
- int card_num = stoi(temp.substr(0, temp.find(",")));
- string card_stema = temp.substr(temp.find(",") + 1, temp.length());
- deck.push_back(Card(card_num, card_stema));
- }
- } else if (subiect == "play_game") {
- cout << "Pachet pentru Backjack" << endl;
- cout << "Pachet pentru Backjack" << endl;
- cout << "Pachet pentru Backjack" << endl;
- }
- }
- // check_cards
- // 4,romb
- // 3,rosu
- // 12,trefla
- // 10,negru
- // 7,rosu
- // 9,romb
- // 7,negru
- // 4,rosu
Add Comment
Please, Sign In to add comment