Advertisement
evage

Untitled

Nov 21st, 2021
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <set>
  4. #include <time.h>
  5. #define NUMBSIZE 4
  6. #define f(i,a,b) for (i = a; i < b; ++i)
  7. using namespace std;
  8. int comparator(string src, string dest) {
  9.     int i;
  10.     int cnt = 0;
  11.     f(i, 0, NUMBSIZE)
  12.         if (src[i] == dest[i])
  13.         {
  14.             cout << '+';
  15.             ++cnt;
  16.         }
  17.         else
  18.             cout << '-';
  19.     return cnt;
  20. }
  21. string createNumber() {
  22.     int i,j;
  23.     bool flag = true;
  24.     set<char> uniqueSymbols;
  25.     string ret;
  26.     while (flag) {
  27.         ret = "";
  28.         f(i, 0, NUMBSIZE)
  29.             ret += to_string(rand() % 10);
  30.         f(j, 0, NUMBSIZE)
  31.             uniqueSymbols.insert(ret[j]);
  32.         if (uniqueSymbols.size() == 4 && ret[0] != '0')
  33.             flag = false;
  34.         uniqueSymbols.clear();
  35.     }
  36.     return ret;
  37. }
  38. int main() {
  39.     srand(time(NULL));
  40.     string src = createNumber();
  41.     string comp;
  42.     int health;
  43.     cout << "enter your number\n";
  44.     do
  45.     {
  46.         health = 4;
  47.         cin >> comp;
  48.         health -= comparator(src, comp);
  49.         cout << '\n';
  50.     } while (health > 0);
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement