Created
June 3, 2017 01:54
-
-
Save algon-320/66e36a068f2f0762ced7fefad0d487e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
string reverseChallenge(string s) { | |
string t, ans; | |
vector<int> len; | |
int l = 0; | |
s += ' '; | |
for(size_t i = 0; i < s.size(); i++) { | |
if(s[i]==' ') { | |
len.push_back(l); | |
l=0; | |
} | |
else { | |
l++; | |
t += s[i]; | |
} | |
} | |
reverse(t.begin(), t.end()); | |
for(size_t i = 0; i < t.size(); i++) { | |
if('a' <= t[i] && t[i] <= 'z') | |
t[i]='z'-(t[i]-'a'); | |
} | |
int idx = 0; | |
for(size_t i = 0; i < len.size(); i++) { | |
ans += t.substr(idx, len[i]); | |
idx += len[i]; | |
if(i != len.size()-1) ans += ' '; | |
} | |
return ans; | |
} | |
int main() { | |
string s; | |
getline(cin, s); | |
cout<<reverseChallenge(s)<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment