C
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int n,k;
char s[500005];
int qr,dg,dl,dr;
signed main(){
cin >> n >> k >> s+1;
int lx = 1,rx = 0,op = 0,gs = 0;
for(int i = 1;i <= n&&op <= k;++ i){
if(s[i] == '1'){
if(s[i-1] != '1') op++;
rx++;
gs++;
if(op == k-1) qr = rx;
if(op == k) dg = gs,dl = lx,dr = rx;
}
else if(s[i] == '0'){
gs = 0;
lx = i+1;
rx = i;
}
}
for(int i = 1;i <= n;++ i){
if(i == dl){
i = dr;
continue;
}
cout << s[i];
if(i == qr){
for(int j = 1;j <= dg;++ j)
cout << 1;
}
}
return 0;
}
D
点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
char s[200005];
int q,n;
int w[200005],cn;
char bian(int x){
if(x >= 'a'&&x <= 'z') return x-'a'+'A';
else return x-'A'+'a';
}
signed main(){
cin >> s+1 >> q;
n = strlen(s+1);
while(q--){
cn = 0;
int k;
cin >> k;
int g = (k+n-1)/n;
int gk = k%n;
if(gk == 0) gk = n;
int t = g,a = 1;
while(t){
w[++cn] = a;
t >>= 1;
a *= 2;
}
int c = 0;
for(int i = cn;i > 1;-- i){
if(g > w[i]){
g %= w[i],c++;
if(g == 0) g = w[i];
}
}
if(g == 2)c++;
c %= 2;
if(c == 1) cout << bian(s[gk]) << " ";
else cout << s[gk] << " ";
}
return 0;
}