String Transformations locked - Hacker Rank Program

Problem Statement

Given a string S, you need to perform Q transformations of the form (a,b). For each transformation, you need to reverse the substring s[a...b] and then print the transformed string. This change is permanently applied on the string, i.e., each tranformation will be done on the output of previous transformation.

Input Format

The first line of input contains the string S.
This is followed by integer Q in the next line.
Then Q lines follow, each containing two space-separated integers, a and b.

Constraints

  • 1length(S)1000

  • 1Q1000

  • 0ab<length(S)

Output Format

For each transformation, print the answer in a new line.

Sample Input

abcdef 4 0 0 0 5 0 2 0 1

Sample Output

abcdef fedcba defcba edfcba

Explanation

  • After the first operation, the string is now "abcdef".

  • After the second operation, the string is now "fedcba".

  • After the third operation, the string is now "defcba".

  • After the fourth operation, the string is now "edfcba".

MY SOLUTION:

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

 string a;

int main() {
    int t, i,x,y;
    cin>>a;
    cin>>t;

    for(i=0;i<t;i++)
    {
      cin>>x>>y;
      while(x<y)
      {
         char temp;
          temp=a[y];
          a[y]=a[x];
          a[x]=temp;
          y--;
          x++;
      }
        cout<<a<<endl;
    }
   
   
    return 0;
}
 


Convert resultset object to list of map

Convert the resultset object to list of map In some cases, while we doing API automation, we need to fetch the value from the DB and hav...