Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- size_t length(int* box, const size_t n) {
- int pattern[] = { 1, 2, 3 };
- auto count = 0U;
- for (auto i = 0U, j = 0U; i < n; ++i) {
- if (box[i] == pattern[j]) ++j;
- if (j == size(pattern)) {
- count += 3U;
- j = 0U;
- }
- }
- return count;
- }
- int main() {
- int box[] = { 1, 4, 2, 3, 5, 1, 1, 3, 2, 5, 6, 3, 1, 2, 0, 3, 1, 2 };
- for (auto value : box) cout << ' ' << value;
- cout.put('\n');
- auto quantity = length(box, size(box));
- cout << ' ' << quantity << '\n';
- cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement