Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. size_t length(int* box, const size_t n) {
  4. int pattern[] = { 1, 2, 3 };
  5. auto count = 0U;
  6. for (auto i = 0U, j = 0U; i < n; ++i) {
  7. if (box[i] == pattern[j]) ++j;
  8. if (j == size(pattern)) {
  9. count += 3U;
  10. j = 0U;
  11. }
  12. }
  13. return count;
  14. }
  15. int main() {
  16. int box[] = { 1, 4, 2, 3, 5, 1, 1, 3, 2, 5, 6, 3, 1, 2, 0, 3, 1, 2 };
  17. for (auto value : box) cout << ' ' << value;
  18. cout.put('\n');
  19. auto quantity = length(box, size(box));
  20. cout << ' ' << quantity << '\n';
  21. cin.get();
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement