• B. Pasha and String


    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.

    Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent m days performing the following transformations on his string — each day he chose integer ai and reversed a piece of string (a segment) from position ai to position |s| - ai + 1. It is guaranteed that ai ≤ |s|.

    You face the following task: determine what Pasha's string will look like after m days.

    Input

    The first line of the input contains Pasha's string s of length from 2 to 2·105 characters, consisting of lowercase Latin letters.

    The second line contains a single integer m (1 ≤ m ≤ 105) —  the number of days when Pasha changed his string.

    The third line contains m space-separated elements ai (1 ≤ ai; ai ≤ |s|) — the position from which Pasha started transforming the string on the i-th day.

    Output

    In the first line of the output print what Pasha's string s will look like after m days.

    Sample test(s)
    Input
    abcdef
    1
    2
    Output
    aedcbf
    Input
    vwxyz
    2
    2 2
    Output
    vwxyz
    Input
    abcdef
    3
    1 2 3
    Output
    fbdcea

    翻转的子串是中心对称的。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <string>
     7 #include <vector>
     8 #include <set>
     9 #include <map>
    10 #include <queue>
    11 #include <stack>
    12 #include <sstream>
    13 #include <iomanip>
    14 using namespace std;
    15 const int INF=0x4fffffff;
    16 const int EXP=1e-6;
    17 const int MS=100005;
    18 
    19 char str[2*MS];
    20 int n;
    21 int flag[MS];
    22 
    23 int main()
    24 {
    25       scanf("%s",str);
    26       scanf("%d",&n);
    27       memset(flag,0,sizeof(flag));
    28       int len=strlen(str);
    29       int x;
    30       for(int i=0;i<n;i++)
    31       {
    32             scanf("%d",&x);
    33             flag[x-1]++;
    34       }
    35       for(int i=1;i<len/2;i++)
    36             flag[i]+=flag[i-1];
    37       for(int i=0;i<len/2;i++)
    38       {
    39             if(flag[i]%2==0)
    40                   continue;
    41             else
    42             {
    43                   char c=str[i];
    44                   str[i]=str[len-1-i];
    45                   str[len-1-i]=c;
    46             }
    47       }
    48       printf("%s
    ",str);
    49       return 0;
    50 }
  • 相关阅读:
    转:asp.net mvc下的多语言方案 包含Html,Javascript和图片
    转:在ASP.NET MVC中通过URL路由实现对多语言的支持
    转:C# lock用法
    转:SQL 关于apply的两种形式cross apply 和 outer apply
    在ASP.NET MVC 中获取当前URL、controller、action
    转:Newtonsoft.Json高级用法
    转:jQuery插件开发全解析
    转:ASP.NET MVC 多语言实现技巧 最简、最易维护和最快速开发
    转:前端js、jQuery实现日期格式化、字符串格式化
    转:.Net内存泄露原因及解决办法
  • 原文地址:https://www.cnblogs.com/767355675hutaishi/p/4375367.html
Copyright © 2020-2023  润新知