JosepRivaille

X58185: Casino binari

Jul 25th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.   int e;
  9.   char c;
  10.   string nom;
  11.   int ap, alt;
  12.   cin >> e;
  13.  
  14.   int count_z = 0;
  15.   int count_u = 0;
  16.   int count_a = 0;
  17.   bool first = true;
  18.   int aux;
  19.   while (cin >> c && c != '.') {
  20.    
  21.     if (c == '0') ++count_z;
  22.     else ++count_u;
  23.    
  24.     if (first) {
  25.       if (c == '0') aux = 0;
  26.       else aux = 1;
  27.       first = false;
  28.     }
  29.     else {
  30.       if (aux == 0 && c == '1') {
  31.      ++count_a;
  32.      aux = 1;
  33.       }
  34.       else if (aux == 1 && c == '0') {
  35.      ++count_a;
  36.      aux = 0;
  37.       }
  38.     }
  39.   }
  40.   cout << count_z << " ceros" << endl;
  41.   cout << count_u << " uns" << endl;
  42.   cout << count_a << " alternancies" << endl;
  43.   int aposta_guanyadora = 2;
  44.   bool trobat = false;;
  45.   if (count_z > count_u) aposta_guanyadora = 0;
  46.   else if (count_z < count_u) aposta_guanyadora = 1;  
  47.   else {
  48.     cout << "Casino guanya 50% apostes" << endl << "50% apostes al pot" << endl;
  49.     trobat = true;
  50.   }
  51.   while (!trobat && cin >> nom >> ap >> alt) {
  52.     if (ap == aposta_guanyadora) {
  53.       trobat = true;
  54.       if (alt <= count_a + e && alt >= count_a - e) cout << nom << " guanya 50% apostes" << endl << nom << " guanya pot actual" << endl;
  55.       else cout << nom << " guanya 50% apostes" << endl;
  56.       cout << "50% apostes al pot" << endl;
  57.     }
  58.   }
  59.   if (!trobat) {
  60.     cout << "100% apostes al pot" << endl;
  61.   }
  62. }
  63.  
  64. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment