-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3614.cpp
More file actions
31 lines (31 loc) · 887 Bytes
/
Copy path3614.cpp
File metadata and controls
31 lines (31 loc) · 887 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
class Solution {
public:
char processStr(string s, long long k) {
long long length = 0;
for (auto c : s) {
if (c >= 'a' && c <= 'z') length++;
else if (c == '*') length = max(0LL, length - 1);
else if (c == '#') length *= 2;
}
if (k >= length) return '.';
for (int i = s.size() - 1; i >= 0; --i) {
int c = s[i];
if (c >= 'a' && c <= 'z') {
length--;
if (length == k) return c;
}
else if (c == '*') {
length++;
}
else if (c == '#') {
long long half = length / 2;
if (k >= half) k -= half;
length = half;
}
else if (c == '%') {
k = length - k - 1;
}
}
return '.';
}
};