-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.cpp
More file actions
51 lines (51 loc) · 1.37 KB
/
source.cpp
File metadata and controls
51 lines (51 loc) · 1.37 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
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
int main() {
unsigned int endRange = 50, p = 1;
cout << "Welcome to a guessing game!" << endl;
cout << "Enter the end of a range (2-1000) : ";
cin >> endRange;
if (endRange > 1000) endRange = 1000;
else if (endRange < 2) endRange = 2;
vector<int> v;
do {
v.push_back(p);
p = (p << 1);
} while (p < endRange);
map<int, vector<int>> mp;
for (int i = 0; i < p; i++) {
vector<int> range; int sum = 0;
for (int j = 0; j < v.size(); j++) {
if (i & (1 << j)) {
sum += v[j];
range.push_back(v[j]);
}
}
for (int j : range)
mp[j].push_back(sum);
}
cout << "pick a number in your head from 1 to " << p << " if you finished picking hit enter!";
cin.get();
cin.get();
cout << endl;
int sum = 0;
for (const auto& [a, vv] : mp) {
cout << "Do you see your number in the following list? (y/n)" << endl;
for (const int& i : vv)
cout << i << ' ';
cout << endl << "> ";
string str;
cin >> str;
if (str[0] == 'y') sum += vv[0];
cout << endl << endl;
}
cout << "Do you see your number in the following list? (y/n)" << endl;
string str;
cout << p << endl << "> ";
cin >> str;
if (str[0] == 'y') sum = p;
cout << (sum ? (("You picked: " + to_string(sum))) : "You either didn't see your number or you picked a number that falls out of the range! :)") << endl;
}