ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1226. esreveR redrO

my simple accepted code
Posted by kazanski 29 Oct 2017 07:20
#include <iostream>
#include <iomanip>
#include <map>
#include <vector>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int letter(char c)
{
    return (('a'<=c&&c<='z')||('A'<=c&&c<='Z'));
}

int main()
{
    //freopen("a","r",stdin);
    string s;
    while(getline(cin,s))
    {
        vector<int> l,r;
        for (size_t i=0;i<s.length();i++)
        {
            if (letter(s[i]))
            {
                if (!i||!letter(s[i-1]))
                {
                    l.push_back(i);
                }
                if (i+1==s.length()||!letter(s[i+1]))
                {
                    r.push_back(i+1);
                }
            }
        }
        for (int i=0;i<l.size();i++)
        {
            reverse(s.begin()+l[i],s.begin()+r[i]);
        }
        cout << s << endl;
    }
    return 0;
}