forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththinkingofanumber.cpp
78 lines (66 loc) · 1.76 KB
/
thinkingofanumber.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
// Pairs: First index is operation,
// second is number
// 1: Less Than
// 2: Greater than
// 3: Divisible by
int main() {
int n;
while(cin >> n && n != 0) {
vector<pair<int, int>> commands;
for(int i = 0; i < n; i++) {
string command, garbage;
int temp;
cin >> command >> garbage >> temp;
int op;
if(command == "less") {
op = 1;
}
if(command == "greater") {
op = 2;
}
if(command == "divisible") {
op = 3;
}
commands.push_back({op, temp});
}
sort(commands.begin(), commands.end());
if(commands[0].first != 1) {
cout << "infinite" << endl;
continue;
}
vector<bool> possible;
possible.resize(commands[0].second, true);
for(auto i : commands) {
if(i.first == 1) {
continue;
}
if(i.first == 2) {
for(int j = 0; j < possible.size() && j <= i.second; j++) {
possible[j] = false;
}
}
if(i.first == 3) {
for(int j = 0; j < possible.size(); j++) {
if(j % i.second != 0) {
possible[j] = false;
}
}
}
}
bool printed = false;
for(int i = 1; i < possible.size(); i++) {
if(possible[i]) {
printed = true;
cout << i << " ";
}
}
if(!printed) {
cout << "none";
}
cout << endl;
}
}