SKREFI

Coco-LabPOOv1

Jan 31st, 2021 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ui uint8_t
  5.  
  6. class Card {
  7.     int numar;  // nu stiu ce ce dar nu mergea cu uint8_t
  8.     string stema;
  9.  
  10.    public:
  11.     Card(ui nr, string stema) : numar(nr), stema(stema) {}
  12.  
  13.     friend ostream& operator<<(ostream& os, const Card& card) {
  14.         os << card.numar << "," << card.stema;
  15.         return os;
  16.     }
  17.  
  18.     friend bool operator==(const Card& a, const Card& b) {
  19.         return a.numar == b.numar && a.stema == b.stema;
  20.     }
  21.  
  22.     // bool operator==(const Card& c) const {
  23.     //     return this->numar == c.numar && this->stema == c.stema;
  24.     // }
  25.  
  26.     // pentru set, dar nu merge :/
  27.     // struct HashFunction {
  28.     //     size_t operator()(const Card& c) const {
  29.     //         size_t xHash = std::hash<int>()(c.numar);
  30.     //         size_t yHash;
  31.  
  32.     //         if (c.stema == "rosu") {
  33.     //             yHash = std::hash<int>()(1);
  34.     //         } else if (c.stema == "romb") {
  35.     //             yHash = std::hash<int>()(2);
  36.     //         } else if (c.stema == "negru") {
  37.     //             yHash = std::hash<int>()(3);
  38.     //         } else if (c.stema == "trefla") {
  39.     //             yHash = std::hash<int>()(4);
  40.     //         }
  41.     //         return xHash ^ yHash;
  42.     //     }
  43.     // };
  44. };
  45.  
  46. int main() {
  47.     string subiect;
  48.     ifstream fin("blackjack.in");
  49.     // cout << "Subiect: ";
  50.     fin >> subiect;
  51.  
  52.     if (subiect == "check_cards") {
  53.         // nu se specifica numarul de carti in datele de itnrate asa ca sunt obligat sa folosesc un fisier
  54.  
  55.         string temp;
  56.  
  57.         int no_cards = 0;
  58.         vector<Card> deck;
  59.  
  60.         while (fin >> temp) {
  61.             if (no_cards > 52) {
  62.                 // 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
  63.                 // ori s-au bagat duplicate ori carti care nu exista.
  64.                 cout << "Pachet masluit" << endl;
  65.                 return -1;
  66.             }
  67.  
  68.             int card_num = stoi(temp.substr(0, temp.find(",")));
  69.             string card_stema = temp.substr(temp.find(",") + 1, temp.length());
  70.  
  71.             if (card_num < 2 || card_num > 14) {
  72.                 cout << "Pachet masluit" << endl;
  73.                 return -1;
  74.             }
  75.             if (card_stema == "romb" || card_stema == "rosu" || card_stema == "negru" || card_stema == "trefla") {
  76.                 // all good
  77.                 Card c(card_num, card_stema);
  78.  
  79.                 if (find(deck.begin(), deck.end(), c) != deck.end()) {
  80.                     cout << "Pachet masluit" << endl;
  81.                     return -1;
  82.                 }
  83.  
  84.                 deck.push_back(c);
  85.                 no_cards++;
  86.  
  87.                 // cout << "Card number " << no_cards << ": " << c << endl;
  88.                 continue;
  89.             } else {
  90.                 cout << "Pachet masluit" << endl;
  91.                 return -1;
  92.             }
  93.         }
  94.         cout << "Pachet pentru Backjack" << endl;
  95.     } else if (subiect == "shuffle_cards") {  // imi asum ca deckul a fost verificat
  96.        
  97.         string temp;
  98.  
  99.         vector<Card> deck;
  100.  
  101.         int a1, x1, c1;
  102.         int a2, x2, c2;
  103.  
  104.         cin >> a1 >> x1 >> c1 >> a2 >> x2 >> c2;
  105.  
  106.         while (fin >> temp) {
  107.             int card_num = stoi(temp.substr(0, temp.find(",")));
  108.             string card_stema = temp.substr(temp.find(",") + 1, temp.length());
  109.             deck.push_back(Card(card_num, card_stema));
  110.         }
  111.  
  112.  
  113.     } else if (subiect == "play_game") {
  114.         cout << "Pachet pentru Backjack" << endl;
  115.         cout << "Pachet pentru Backjack" << endl;
  116.         cout << "Pachet pentru Backjack" << endl;
  117.     }
  118. }
  119.  
  120. // check_cards
  121. // 4,romb
  122. // 3,rosu
  123. // 12,trefla
  124. // 10,negru
  125. // 7,rosu
  126. // 9,romb
  127. // 7,negru
  128. // 4,rosu
Add Comment
Please, Sign In to add comment