Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <set>
- #include <time.h>
- #define NUMBSIZE 4
- #define f(i,a,b) for (i = a; i < b; ++i)
- using namespace std;
- int comparator(string src, string dest) {
- int i;
- int cnt = 0;
- f(i, 0, NUMBSIZE)
- if (src[i] == dest[i])
- {
- cout << '+';
- ++cnt;
- }
- else
- cout << '-';
- return cnt;
- }
- string createNumber() {
- int i,j;
- bool flag = true;
- set<char> uniqueSymbols;
- string ret;
- while (flag) {
- ret = "";
- f(i, 0, NUMBSIZE)
- ret += to_string(rand() % 10);
- f(j, 0, NUMBSIZE)
- uniqueSymbols.insert(ret[j]);
- if (uniqueSymbols.size() == 4 && ret[0] != '0')
- flag = false;
- uniqueSymbols.clear();
- }
- return ret;
- }
- int main() {
- srand(time(NULL));
- string src = createNumber();
- string comp;
- int health;
- cout << "enter your number\n";
- do
- {
- health = 4;
- cin >> comp;
- health -= comparator(src, comp);
- cout << '\n';
- } while (health > 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement