zoukankan      html  css  js  c++  java
  • HDU 1981 A Special Text Editor

     
    Problem Description
    After AC all the hardest problems in the world , the ACboy 8006 now has nothing to do . So he develops a special text editor.The text editor is so special that 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 will 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 will translate every character in the substring which is in the string from positon A to position B to the NEXT character in alphabetic table.In another word, it will translate 'a' to 'b','b' to 'c' ... 'y' to 'z'. Specially it will 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 is 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 will be "azfedcbh".
    Then after we operate the command "S 2 3", it will be "aagedcbh".

    Now your task is to simulate the process, and output the exact character when you read a "Query" command. Is that easy ? Just come and AC it !
     
    Input
    The first line of the input contains an integer T which means the number of test cases. Then T test cases follow.
    In the first line there are two integers N(0<N<=80000) and C(0<C<=3000) which indicate the length of the string and the number of the commands.
    In the second line there is a string whose length is N and which is 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).
     
    Output
    For each "Query" command, output the character which the text editor reports.
     
     
    Sample Input
    1 8 5
    abcdefzh
    Q 4 R 2 7
    Q 3
    S 2 3
    Q 2
     
    Sample Output
    d
    f
    a
     
     
    Author
    linle
     
     
    Source
     
     
     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<string.h>
     4 #include<stdlib.h>
     5 #include<ctype.h>
     6 #define max(a, b)(a < b ? a : b)
     7 #define N 80010
     8 
     9 char s[N];
    10 
    11 void slove(char s[], int a, int b)
    12 {
    13     int i;
    14     for(i = a ; i <= b ; i++)
    15     {
    16         if(s[i] == 'z')
    17             s[i] = 'a';
    18         else
    19             s[i] += 1;
    20     }
    21 }
    22 int main()
    23 {
    24     int t, len, n;
    25     char ch, ch1;
    26     int a, b, c, i, j, h;
    27     scanf("%d", &t);
    28     while(t--)
    29     {
    30         scanf("%d%d ", &len, &n);
    31         scanf("%s", s);
    32         for(i = 0 ; i < n ; i++)
    33         {
    34             scanf(" %c", &ch);
    35             if(ch == 'Q')
    36             {
    37                 scanf("%d", &c);
    38                 printf("%c
    ", s[c - 1]);
    39             }
    40             else
    41             {
    42                 scanf("%d%d", &a, &b);
    43                 if(ch == 'R')
    44                 {
    45                     for(h = a - 1, j = b - 1 ; h <= j ; h++, j--)
    46                     {
    47                         ch1 = s[h];
    48                         s[h] = s[j];
    49                         s[j] = ch1;
    50                     }
    51                 }
    52                 else if(ch == 'S')
    53                     slove(s, a - 1, b - 1);
    54             }
    55         }
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    七色花基本权限系统(6)- 让EntityFramework Code First自动合并/迁移/数据初始化
    koa 上传图片,上传文件,批量上传文件,批量上传图片...
    js 正则匹配标签,过滤标签不保留内容和过滤标签保留内容,过滤标签的的属性
    js 用xlsx读取excel、json_to_execl、excel_to_json导入导出
    css 心形动画 爱心动画
    NodeJs + koa2 + sequelize-auto + sequelize 搭建项目
    非框架, 纯原生JS “商品详情跳转到商品列表,并记录高度“ 的写法思路
    vue 渲染完成事件
    promise扩展一个stop方法
    vue中引入第三方字体图标库iconfont,及iconfont引入彩色图标
  • 原文地址:https://www.cnblogs.com/yishilin/p/4448341.html
Copyright © 2011-2022 走看看