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 stringsfor 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 spentmdays performing the following transformations on his string—each day he chose integeraiandreverseda piece of string (a segment) from positionaito position|s|-ai+1. It is guaranteed that2·ai≤|s|.
You face the following task: determine what Pasha’s string will look like aftermdays.
Input
The first line of the input contains Pasha’s stringsof length from2to2·105characters, consisting of lowercase Latin letters.
The second line contains a single integerm(1≤m≤105)— the number of days when Pasha changed his string.
The third line containsmspace-separated elementsai(1≤ai;2·ai≤|s|)—the position from which Pasha started transforming the string on thei-th day.
Output
In the first line of the output print what Pasha’s stringswill look like aftermdays.
Sample test(s)
input
abcdef12
output
aedcbf
input
vwxyz22 2
output
vwxyz
input
abcdef31 2 3
output
fbdcea
题意:给出一个字符串,然后进行n次询问(每次的数值是从该数值到len-该数值进行字符串翻转),问n次翻转后字符串的形式。
思路:因为是对称的翻转,,所以可以统计每个字母的翻转次数,如果是奇数次就反转,是偶数次就不用管,然后搞搞就ok了,注意是从1-len。
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace std;typedef long long LL;char str[200010];int cnt[100010];int main(){int n,m,i;int len;while(~scanf("%s",str+1)){len=strlen(str+1);memset(cnt,0,sizeof(cnt));scanf("%d",&n);while(n–){scanf("%d",&m);cnt[m]++;}for(i=1;i<=len/2;i++)cnt[i]+=cnt[i-1];for(i=1;i<=len/2;i++)if(cnt[i]%2)swap(str[i],str[len-i+1]);printf("%s\n",str+1);}return 0;}
最糟糕的行为是抱怨,最易见效 的努力是从自己做起。