B. Pasha and String
2 seconds
256 megabytes
standard input
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 2·ai ≤ |s|.
You face the following task: determine what Pasha's string will look like after m days.
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; 2·ai ≤ |s|) — the position from which Pasha started transforming the string on the i-th day.
In the first line of the output print what Pasha's string s will look like after m days.
abcdef
1
2
aedcbf
vwxyz
2
2 2
vwxyz
abcdef
3
1 2 3
fbdcea 翻转的子串是中心对称的。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
using namespace std;
const int INF=0x4fffffff;
const int EXP=1e-;
const int MS=; char str[*MS];
int n;
int flag[MS]; int main()
{
scanf("%s",str);
scanf("%d",&n);
memset(flag,,sizeof(flag));
int len=strlen(str);
int x;
for(int i=;i<n;i++)
{
scanf("%d",&x);
flag[x-]++;
}
for(int i=;i<len/;i++)
flag[i]+=flag[i-];
for(int i=;i<len/;i++)
{
if(flag[i]%==)
continue;
else
{
char c=str[i];
str[i]=str[len--i];
str[len--i]=c;
}
}
printf("%s\n",str);
return ;
}
最新文章
- 【Android】Android如何一进入一个activity就弹出输入法键盘
- 详解Android定位
- 【POJ】3076 Sudoku
- java 集合框架图
- Lucene 08 - 什么是Lucene的相关度排序 + Java API调整相关度
- centos7下安装python3.6
- log4net:ERROR ConfigureFromXml called with null &#39;element&#39; parameter
- day23-python操作数据库三
- 33. 完全卸载oracle11g步骤
- Mockito学习(zz)
- 内存溢出导致jenkins自动部署到tomcat失败
- Servlet基础笔记
- mysql 导入 csv 格式数据
- rman中 Backup Set 与 Image Copy 优缺点比较
- Java中int与String间的类型转换
- Linux shell(. /path/filename)
- vmware实现物理机和虚拟机复制粘贴
- delphi xe7 多线程调用CMD,使用管道,临界区技术,实现指定用户名,多线程,异步返回CMD命令结果到memo
- python--内置常用模块
- SQL Server调试存储过程
热门文章
- 第三百五十五天 how can I 坚持
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
- c# spring aop的简单例子
- GWT+CodeTemplate+TableCreate快速开发
- MFC如何添加系统消息处理函数?
- 遇见了这个问题:App.config提示错误“配置系统未能初始化”
- rome实现rss订阅与发布
- D. Green and Black Tea
- Flex 拾色器改变背景
- 【AS3 Coder】任务七:初涉PureMVC——天气预报功能实现