-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
245 lines (193 loc) · 5.23 KB
/
Copy pathmain.cpp
File metadata and controls
245 lines (193 loc) · 5.23 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include "main.h"
#include <iostream>
#include <vector>
const int tea_party(const int tea, const int candy) {
return (tea < 5 || candy < 5) ? 0
: (tea >= candy * 2 || candy >= tea * 2) ? 2
: 1;
}
const std::string fizz_string(const std::string str) {
int size = str.size();
if (str[0] == 'f' && str[size - 1] == 'b')
return "FizzBuzz";
if (str[0] == 'f')
return "Fizz";
if (str[size - 1] == 'b')
return "Buzz";
return str;
}
const std::string fizz_string2(const int n) {
if (n % 3 == 0 && n % 5 == 0)
return "FizzBuzz!";
if (n % 3 == 0)
return "Fizz!";
if (n % 5 == 0)
return "Buzz!";
return std::to_string(n) + "!";
}
const bool two_as_one(const int a, const int b, const int c) {
return a + b == c || a + c == b || b + c == a;
}
const int sum67(std::vector<int> nums)
{
int sum = 0;
bool skip = false;
std::vector<int>::iterator it;
for (it = nums.begin(); it != nums.end(); it++)
{
if (*it == 6) skip = true;
else if (*it == 7 && skip) skip = false;
else if (!skip) sum += *it;
}
return sum;
}
const bool has22(const std::vector<int> nums)
{
for (int i = 0; i < nums.size()-1; i++)
if (nums.at(i) == 2 && nums.at(i+1) == 2)
return true;
return false;
}
const bool lucky13(const std::vector<int> nums)
{
for (int i = 0; i < nums.size(); i++)
if (nums.at(i) == 1 || nums.at(i) == 3)
return false;
return true;
}
const bool sum28(const std::vector<int> nums)
{
int sum = 0;
for (int i = 0; i < nums.size(); i++)
if (nums.at(i) == 2)
sum += nums.at(i);
return sum == 8;
}
const bool more14(const std::vector<int> nums)
{
int count = 0;
for (int i = 0; i < nums.size(); i++)
{
if (nums.at(i) == 1) count++;
if (nums.at(i) == 4) count--;
}
return count > 0;
}
const std::vector<int> fizz_array(const int n)
{
std::vector<int> arr;
for (int i = 0; i < n; i++)
arr.push_back(i);
return arr;
}
const bool only14(const std::vector<int> nums)
{
for (int i = 0; i < nums.size(); i++)
if (nums.at(i) != 1 && nums.at(i) != 4)
return false;
return true;
}
const std::vector<std::string> fizz_array2(const int n)
{
std::vector<std::string> arr;
for (int i = 0; i < n; i++)
arr.push_back(std::to_string(i));
return arr;
}
const bool no14(const std::vector<int> nums)
{
bool has1 = false;
bool has4 = false;
for (int i = 0; i < nums.size(); i++)
{
if (nums.at(i) == 1) has1 = true;
if (nums.at(i) == 4) has4 = true;
if (has1 && has4) return false;
}
return !(has1 && has4);
}
const bool is_everywhere(const std::vector<int> nums, const int val)
{
for (int i = 0; i < nums.size()-1; i++)
if (nums.at(i) != val && nums.at(i+1) != val)
return false;
return true;
}
const bool either24(const std::vector<int> nums)
{
bool is2 = false;
bool is4 = false;
for (int i = 0; i < nums.size()-1; i++)
{
if (is2 && is4) return false;
if (nums.at(i) == 2 && nums.at(i+1) == 2) is2 = true;
if (nums.at(i) == 4 && nums.at(i+1) == 4) is4 = true;
}
return is2 != is4;
}
const int match_up(const std::vector<int> nums1, const std::vector<int> nums2)
{
int count = 0;
for (int i = 0; i < nums1.size(); i++)
if (nums1.at(i) != nums2.at(i) && std::abs(nums1[i] - nums2[i]) <= 2)
count++;
return count;
}
const bool has77(const std::vector<int> nums)
{
for (int i = 0; i < nums.size() - 2; i++)
if ((nums.at(i) == 7 && (nums.at(i+1) == 7 || nums.at(i+2) == 7)) || (nums.at(i+1) == 7 && nums.at(i+2) == 7))
return true;
return false;
}
const bool has12(const std::vector<int> nums)
{
bool found = false;
for (int i = 0; i < nums.size(); i++)
{
if (nums[i] == 1 && !found)
found = true;
if (nums[i] == 2 && found)
return true;
}
return false;
}
const bool mod_three(const std::vector<int> nums)
{
for (int i = 0; i < nums.size()-2; i++)
{
if ((
nums.at(i) % 2 == 0 &&
nums.at(i+1) % 2 == 0 &&
nums.at(i+2) % 2 == 0
) || (
nums.at(i) % 2 == 1 &&
nums.at(i+1) % 2 == 1 &&
nums.at(i+2) % 2 == 1
))
return true;
}
return false;
}
#ifndef TESTING
int main() {
std::cout << "\ntea_party:\n";
std::cout << (tea_party(6, 8) == 1 ? "OK" : "FAILED") << std::endl;
std::cout << (tea_party(3, 8) == 0 ? "OK" : "FAILED") << std::endl;
std::cout << (tea_party(20, 6) == 2 ? "OK" : "FAILED") << std::endl;
std::cout << "\nfizz_string:\n";
std::cout << (fizz_string("fig") == "Fizz" ? "OK" : "FAILED") << std::endl;
std::cout << (fizz_string("dib") == "Buzz" ? "OK" : "FAILED") << std::endl;
std::cout << (fizz_string("fib") == "FizzBuzz" ? "OK" : "FAILED")
<< std::endl;
std::cout << "\nfizz_string2:\n";
std::cout << (fizz_string2(1) == "1!" ? "OK" : "FAILED") << std::endl;
std::cout << (fizz_string2(2) == "2!" ? "OK" : "FAILED") << std::endl;
std::cout << (fizz_string2(3) == "Fizz!" ? "OK" : "FAILED") << std::endl;
std::cout << "\ntwo_as_one:\n";
std::cout << (two_as_one(1, 2, 3) ? "OK" : "FAILED") << std::endl;
std::cout << (two_as_one(3, 1, 2) ? "OK" : "FAILED") << std::endl;
std::cout << (!two_as_one(3, 2, 2) ? "OK" : "FAILED") << std::endl;
return 0;
}
#endif