-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd99.cpp
More file actions
65 lines (59 loc) · 1.18 KB
/
d99.cpp
File metadata and controls
65 lines (59 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include "Header.h"
#include <string>
using namespace std;
bool checkSim(string nr) { // return true if has similar numbers
for (int i = 0; i < nr.length() - 1; i++) {
for (int j = i + 1; j < nr.length(); j++) {
if (nr[i] == nr[j]) {
return true;
}
}
}
return false;
}
int getRand() {
srand(time(NULL));
int r = (rand() * rand()) % 10000;
bool fl = true;
while (fl) {
r++;
if (r > 9999) {
r -= (rand() * rand()) % 1000;
}
string nr = to_string(r);
fl = checkSim(nr);
}
return abs(r);
}
int d99() {
cout << "99) " << endl;
int randm = getRand(); //çàãàäàííîå ÷èñëî
string nrandm = to_string(randm);
cout << "Guess the number!" << endl;
//cout << randm << endl;
int n = 0;
while (n != randm) {
int plus = 0;
int minus = 0;
cout << "write num:" << endl;
n = getInt();
string ns = to_string(n);
if (ns.length() != 4 || checkSim(ns)) {
cout << "error.try again" << endl;
}
else {
for (int i = 0; i < ns.length(); i++) {
if (ns[i] == nrandm[i]) {
plus++;
}
else {
minus++;
}
}
cout << "plus: " << plus << endl << "minus: " << minus << endl;
}
}
cout << "congrats!" << endl;
return 0;
}