-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy path0917.cpp
More file actions
38 lines (37 loc) · 761 Bytes
/
0917.cpp
File metadata and controls
38 lines (37 loc) · 761 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
37
38
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
string reverseOnlyLetters(string S)
{
int l = 0, r = S.size() - 1;
while (l < r)
{
if (!isalpha(S[l]))
{
++l;
continue;
}
if (!isalpha(S[r]))
{
--r;
continue;
}
char tmp = S[l];
S[l++] = S[r];
S[r--] = tmp;
}
return S;
}
};
int main()
{
string S = "a-bC-dEf-ghIj";
cout << Solution().reverseOnlyLetters(S);
return 0;
}