-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path722.cpp
35 lines (35 loc) · 959 Bytes
/
722.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
// simple.cpp
class Solution {
public:
vector<string> removeComments(vector<string> &source) {
string temp;
vector<string> res;
int start = 0, i, j;
bool star = false;
for (i = 0; i < source.size(); ++i) {
for (j = 0; j < source[i].size(); ++j) {
if (!star && source[i][j] == '/' && j + 1 < source[i].size()) {
if (source[i][j + 1] == '/')
break;
else if (source[i][j + 1] == '*') {
star = true;
temp += source[i].substr(start, j - start);
++j;
}
} else if (star && source[i][j] == '*' && j + 1 < source[i].size() &&
source[i][j + 1] == '/') {
star = false;
++j;
start = j + 1;
}
}
if (!star) {
temp += source[i].substr(start, j - start);
if (temp.size())
res.emplace_back(move(temp));
start = 0;
}
}
return res;
}
};