-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg005.cpp
More file actions
33 lines (30 loc) · 806 Bytes
/
g005.cpp
File metadata and controls
33 lines (30 loc) · 806 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
#include <iostream>
#include <string>
using namespace std;
static const auto Initialize = [] {
cin.sync_with_stdio(false); cin.tie(nullptr);
return nullptr;
}();
string Reverse(string text) {
string buffer = "";
for (int i = text.size() - 1; i >= 0; --i)
buffer += text[i];
return buffer;
}
int main() {
int last;
bool direction;
string ciphered;
while (cin >> ciphered) {
last = direction = false;
for (int i = 0; i != ciphered.size(); ++i)
if (ciphered[i] == '+' || ciphered[i] == '-') {
cout << (direction ? Reverse(ciphered.substr(last, i - last)) : ciphered.substr(last, i - last));
direction = (ciphered[i] == '-');
last = i + 1;
}
if (last != ciphered.size())
cout << (direction ? Reverse(ciphered.substr(last)) : ciphered.substr(last));
cout << '\n';
}
}