-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path848.cpp
More file actions
42 lines (39 loc) · 1.36 KB
/
848.cpp
File metadata and controls
42 lines (39 loc) · 1.36 KB
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
__________________________________________________________________________________________________
sample 16 ms submission
static int x = []() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}();
class Solution {
public:
string shiftingLetters(string &S, vector<int>& shifts) {
int len = shifts.size();
shifts[len-1] %= 26;
for(int i=1;i<len;i++){
shifts[len-i-1] =shifts[len-i-1]%26 + shifts[len-i];
}
for(int i=0;i<len;i++){
S[i] = 'a'+(shifts[i] + S[i]-'a')%26;
}
return S;
}
};
__________________________________________________________________________________________________
sample 11492 kb submission
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
class Solution {
public:
std::string shiftingLetters(std::string S,
std::vector<int>& shifts) {
std::partial_sum(shifts.rbegin(), shifts.rend(), shifts.rbegin(),
[](int a, int b) {
return (a + b) % 26;
});
for (int i = 0; i < S.size(); ++i) {
S[i] = (S[i] - 'a' + shifts[i]) % 26 + 'a';
}
return S;
}
};
__________________________________________________________________________________________________