-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpizzaOJ.cpp
116 lines (106 loc) · 2.6 KB
/
pizzaOJ.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
vector<string> store;
void solve(char now, string top)
{
if (now == 'Q')
{
store.push_back(top);
return;
}
else
{
char temp = now + 1;
solve(temp, top + now);
solve(temp, top);
}
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
solve('A', "");
while (true)
{
int size0 = 0;
bool ok = false;
vector<string> people;
while (ok == false)
{
string temp = "<";
cin >> temp;
if (temp == "<")
{
return 0;
}
else if (temp == ".")
{
break;
}
++size0;
temp.pop_back();
people.push_back(temp);
}
string ans = "<";
for (int i = 0; i <= 65535; ++i)
{
string top = store[i];
int size0 = people.size();
bool allSatisfied = true;
for (int i = 0; i <= size0 - 1; ++i)
{
int size1 = people[i].size();
bool satisfied = false;
for (int j = 0; j <= size1 - 1; j += 2)
{
bool find0 = top.find(people[i][j + 1]) != string::npos;
if (people[i][j] == '+')
{
if (find0 == true)
{
satisfied = true;
break;
}
}
else
{
if (find0 == false)
{
satisfied = true;
break;
}
}
}
if (satisfied == false)
{
allSatisfied = false;
break;
}
}
if (allSatisfied == true)
{
ans = top;
break;
}
}
if (ans == "<")
{
cout << "No pizza can satisfy these requests.\n";
}
else
{
cout << "Toppings: " << ans << '\n';
}
}
cout.flush();
return 0;
}