-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrip.cpp
More file actions
44 lines (36 loc) · 679 Bytes
/
Strip.cpp
File metadata and controls
44 lines (36 loc) · 679 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
39
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
// Strip String, O(n)
string strip(const string &s, const char ch = ' ') {
int n = s.size();
while (n > 0 && s[n - 1] == ch) {
n--;
}
string res = "";
for (int i = 0; i < n; i++) {
if (s[i] == ch) {
continue;
}
while (i < n) {
res += s[i];
i++;
}
}
return res;
}
void solve() {
string s;
getline(cin, s);
s = strip(s);
cout << s << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}