-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemsInContainer.cpp
42 lines (35 loc) · 993 Bytes
/
ItemsInContainer.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
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
vector<int> noOfitems(string s, vector<int>& start, vector<int>& end) {
vector<int> res;
int size = start.size();
int count = 0;
int count_closed = 0;
bool open = false;
for (int i = 0; i < size; i++) {
count = 0; count_closed = 0;
for (int j = start[i]; j < end[i]; j++) {
if (!open && s[j] == '|')
open = true;
else if (open && s[j] == '*')
count++;
else if (open && s[j] == '|') {
count_closed += count;
count = 0;
}
}
res.push_back(count_closed);
}
return res;
}
int main() {
string s = "*|*|*|*********|***|****";
vector<int> start{ 1,3 };
vector<int> end{ 25,21 };
vector<int> res = noOfitems(s, start, end);
for (int i = 0; i < res.size(); i++)
cout << res[i] << " ";
return 0;
}