Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <string>
- using namespace std;
- int comp(string src, string ent) {
- int a = 0;
- for (int i = 0; i < 4; ++i) {
- if (src[i] == ent[i]) {
- cout << "+";
- ++a;
- }
- else cout << "-";
- }
- return a;
- }
- string createNum() {
- bool flag = true;
- set<char> uniqueSymbols;
- string str;
- while (flag) {
- str = "";
- for (int i = 0; i < 4; ++i) {
- str += to_string(rand() % 10);
- }
- for (int j = 0; j < 4; ++j) {
- uniqueSymbols.insert(str[j]);
- }
- if (uniqueSymbols.size() == 4 && str[0] != '0')
- flag = false;
- uniqueSymbols.clear();
- }
- return str;
- }
- int main() {
- srand(time(NULL));
- setlocale(LC_ALL, "ru");
- string src = createNum();
- cout << src << endl;
- cout << "Введите число:" << endl;
- string ent;;
- int pluses;
- do {
- pluses = 4;
- cin >> ent;
- pluses -= comp(src, ent);
- cout << endl;
- } while (pluses > 0);
- cout << "Успех!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement