Advertisement
malixds_

Untitled

Nov 25th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int comp(string src, string ent) {
  7.     int a = 0;
  8.     for (int i = 0; i < 4; ++i) {
  9.         if (src[i] == ent[i]) {
  10.             cout << "+";
  11.             ++a;
  12.         }
  13.         else cout << "-";
  14.     }
  15.     return a;
  16. }
  17.  
  18. string createNum() {
  19.     bool flag = true;
  20.     set<char> uniqueSymbols;
  21.     string str;
  22.     while (flag) {
  23.         str = "";
  24.         for (int i = 0; i < 4; ++i) {
  25.             str += to_string(rand() % 10);
  26.         }
  27.         for (int j = 0; j < 4; ++j) {
  28.             uniqueSymbols.insert(str[j]);
  29.         }
  30.         if (uniqueSymbols.size() == 4 && str[0] != '0')
  31.             flag = false;
  32.             uniqueSymbols.clear();
  33.         }
  34.     return str;
  35. }
  36. int main() {
  37.     srand(time(NULL));
  38.     setlocale(LC_ALL, "ru");
  39.     string src = createNum();
  40.     cout << src << endl;
  41.     cout << "Введите число:" << endl;
  42.     string ent;;
  43.     int pluses;
  44.     do {
  45.         pluses = 4;    
  46.         cin >> ent;
  47.         pluses -= comp(src, ent);
  48.         cout << endl;
  49.     } while (pluses > 0);
  50.     cout << "Успех!";
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement