-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path604.cpp
More file actions
36 lines (32 loc) · 736 Bytes
/
Copy path604.cpp
File metadata and controls
36 lines (32 loc) · 736 Bytes
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
// simple.cpp
class StringIterator {
vector<pair<int, int>> res;
int off;
public:
StringIterator(string compressedString) {
stringstream ss(compressedString);
char ch;
int val;
while (!ss.eof()) {
ss >> ch;
ss >> val;
res.push_back(pair<int, int>(ch, val));
}
off = 0;
}
char next() {
if (off < res.size()) {
char ch = res[off].first;
off += (--res[off].second == 0);
return ch;
}
return ' ';
}
bool hasNext() { return off < res.size(); }
};
/**
* Your StringIterator object will be instantiated and called as such:
* StringIterator obj = new StringIterator(compressedString);
* char param_1 = obj.next();
* bool param_2 = obj.hasNext();
*/