HDU 1981 A Special Text Editor

Source: Internet
Author: User

problem DescriptionAfter AC all the hardest problems on the world, the Acboy 8006 now have nothing to do. So he develops a special text editor. The text editor is so special This it only supports 3 special operation: "Reverse", "Shift" and "Query".

1.The "Reverse" command has 2 parameters A and B.
The format is "R A B". After the command executed, the editor would reverse the substring which is in the string from position A to position B.

2.The "Shift" command also has 2 parameters A and B.
The format is "S A B". After the command executed, the editor would translate every character in the substring which was in the string from Positon A to position B to the NEXT character in alphabetic table. In another word, it'll translate ' a ' to ' B ', ' B ' to ' C ' ... ' Y ' to ' z '. Specially it would translate ' z ' to ' a '.

3.The "Query" command has only 1 parameter A.
The format is "Q A". When the text editor receives the Command,it just reports the character which was in the postion A of the string now.


For example, let's consider the string "Abcdefzh" whose length is 8.
After we operate the command "R 2 7", the string would be "AZFEDCBH".
Then after we operate the command "S 2 3", it would be "AAGEDCBH".

Now your task was to simulate the process, and the output of the exact character when you read a "Query" command. Is this easy? Just come and AC it!

InputThe first line of the input contains an integer T which means the number of the test cases. Then T test cases follow.
In the first line there is integers N (0<n<=80000) and C (0<c<=3000) which indicate the length of the Strin G and the number of the commands.
The second line there are a string whose length is N and which are only consisted of lowercase letters.
Then C lines follow. Each line describes a command in the form of ' Q a ' or ' R a B ' or ' S a B ' (0<a<=b<=n).

OutputFor each "Query" command, output the character which the text editor reports. Sample Input5abcdefzhQ 4R 2 7Q 3S 2 3Q 2

Sample OutputDFA Authorlinle Source2008 Hangzhou Electric Training Team Tryouts
1#include <stdio.h>2#include <math.h>3#include <string.h>4#include <stdlib.h>5#include <ctype.h>6 #defineMax (A, B) (a < b? a:b)7 #defineN 800108 9 CharS[n];Ten  One voidSlove (CharS[],intAintb) A { -     inti; -      for(i = A; I <= B; i++) the     { -         if(S[i] = ='Z') -S[i] ='a'; -         Else +S[i] + =1; -     } + } A intMain () at { -     intT, Len, N; -     Charch, ch1; -     intA, B, C, I, J, H; -scanf"%d", &t); -      while(t--) in     { -scanf"%d%d", &len, &n); toscanf"%s", s); +          for(i =0; I < n; i++) -         { thescanf"%c", &ch); *             if(ch = ='Q') $             {Panax Notoginsengscanf"%d", &c); -printf"%c\n", S[c-1]); the             } +             Else A             { thescanf"%d%d", &a, &b); +                 if(ch = ='R') -                 { $                      for(h = A-1, j = B-1; H <= J; h++, j--) $                     { -CH1 =S[h]; -S[H] =S[j]; theS[J] =ch1; -                     }Wuyi                 } the                 Else if(ch = ='S') -Slove (S, A-1, B-1); Wu             } -         } About     } $     return 0; -}

HDU 1981 A Special Text Editor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.