jhljx又來了(V)
Problem Description
經過了jhljx上個學期對大家的洗禮,大家對他也不陌生了。於是這個學期他準備捲土重來了。。
-=-
聽說大家開始學習數據結構。唔呼呼~~
給你一個字符串,設字符串的長度爲k。然後jhljx給出了一些位置a[i],那麼你需要將i~k-i+1這一個子串進行反轉操作。
然後jhljx希望知道最終的序列是什麼,請你快來幫幫他。
Input
輸入多組數據。
每組數據第一行爲一個字符串,字符串長度爲k。(k<=100000)
第二行爲一個數n(1<=n<=100000)。
接下來爲n個數a[i](1<=n<=k/2)。
Output
輸出最終的字符串序列。
Sample Input
abcdef 1 2 vwxyz 2 2 2 abcdef 3 1 2 3
Sample Output
aedcbf vwxyz
fbdcea
fsy的思想:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define clr(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn = 100010;
int a[maxn];
char str[maxn];
int n;
int main()
{
int x;
while(~scanf("%s",str+1))
{
scanf("%d",&n);
clr(a,0);
for(int i=1; i<=n; ++i) {
scanf("%d",&x);
a[x]^=1;
}
int l=strlen(str+1);
int f=0;
for(int i=1; i<=l/2; ++i) {
f^=a[i];
if(f) swap(str[i],str[l-i+1]);
}
cout<<str+1<<endl;
}
return 0;
}