fork download
  1. #include<bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define ll long long
  5. #define el cout<<"\n"
  6. #define sz(x) (int)(x).size()
  7. #define all(x) (x).begin(),(x).end()
  8. #define f0(i,n) for(int i=0;i<n;i++)
  9. #define f1(i,n) for(int i=1;i<=n;i++)
  10. #define fz(i,a,n,z) for(int i=a;i<n;i+=z)
  11. #define rep(i,a,n,z) for(int i=a;i>n;i-=z)
  12. #define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  13. #define file(name) freopen(name".inp","r",stdin);freopen(name".out","w",stdout);
  14. using namespace std;
  15. const int maxn = 200010;
  16. const int N = 2e5 + 5;
  17. int main()
  18. {
  19. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  20. string s;
  21. int k;
  22. cin >> s >> k;
  23. char pos[s.size()] = {};
  24. for (int i = 0; i < s.size(); ++i) {
  25. if (s[i] == 'a') {
  26. pos[i + k] = 'a';
  27. }
  28. else {
  29. if (pos[i] == 'a') {
  30. int cnt = 0;
  31. bool meetA = false;
  32. for (int j = i - 1; j >= 0; --j) {
  33. if (s[j] != 'a') {
  34. if (meetA) {
  35. break;
  36. }
  37. }
  38. else {
  39. ++cnt;
  40. meetA = true;
  41. }
  42. }
  43. pos[i - cnt] = s[i];
  44. }
  45. else {
  46. if (s[i] == 'a') {
  47.  
  48. }
  49. pos[i] = s[i];
  50. }
  51. }
  52. }
  53. for (int i = 0; i < s.size(); ++i) {
  54. if (pos[i] < 'a' || pos[i] > 'z') {
  55. cout << s[i + k - 1];
  56.  
  57. }
  58. else cout << pos[i];
  59. }
  60. return 0;
  61. }
  62.  
  63.  
  64.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty