Sunday, November 20, 2016

URI Solution 1235 Inside Out in C++ language


URI Online Judge | 1235

Inside Out

By TopCoder*  USA
Timelimit: 1
Your printer has been infected by a virus and is printing gibberish. After staring at several printed pages for a while, you realize that it is printing every line inside-out. In other words, the left half of each line is being printed starting in the middle of the page and proceeding out toward the left margin. Similarly, the right half of each line is being printed starting at the right margin and proceeding in toward the middle of the page.

For example, the line:
THIS LINE IS GIBBERISH

is being printed as:
I ENIL SIHTHSIREBBIG S

In the same way, the line " MANGOS " is being printed as "NAM  SOG".Your task is to unscramble a String line from its printed form back into its original order. You can assume that line contains an even number of characters.

Input

The input contains many test cases. The first line of input contains an integer N that indicates the number of test cases. Follow N lines, each one with a string with the maximum of 100 uppercase letters ('A'-'Z') and spaces (' '). that must be unscrambled from its printed form back into its original order, like example above.

Output

Each line of input must produce a line of output, with the decoded message, like example above.
Sample InputSample Output
5
I ENIL SIHTHSIREBBIG S
LEVELKAYAK
H YPPAHSYADILO
ABCDEFGHIJKLMNOPQRSTUVWXYZ
VOD OWT SNEH HCNERF EGDIRTRAP A DNA SE
THIS LINE IS GIBBERISH
LEVELKAYAK
HAPPY HOLIDAYS
MLKJIHGFEDCBAZYXWVUTSRQPON
FRENCH HENS TWO DOVES AND A PARTRIDGE


URI Solution 1235 Inside Out in C++ language


#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int n, size;
    string s;
     
    cin >> n;
     
    for (int i = 0; i <= n; ++i) {
         
        getline(cin, s);
        if(i == 0)
            continue;
        size = s.length();       
        vector<char> v(size);
        for(int j = 0; j < size; ++j){v[j] = s[j];}
         
        reverse(v.begin(), v.begin() + (size/2));
        reverse(v.begin() + (size/2), v.begin() + size);
         
        for(int j = 0; j < size; ++j){cout << v[j];}
        cout << endl;
    }
     
    return 0;
}

Download the main Code From Dropbox (If any add occur please click skip button)

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.