fork download
  1. #include <bits/stdc++.h>
  2. // iostream is too mainstream
  3. #include <cstdio>
  4. // bitch please
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <cstdlib>
  8. #include <vector>
  9. #include <set>
  10. #include <map>
  11. #include <queue>
  12. #include <stack>
  13. #include <list>
  14. #include <cmath>
  15. #include <iomanip>
  16. #include <time.h>
  17. #define dibs reserve
  18. #define OVER9000 1234567890123456789LL
  19. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  20. #define tisic 47
  21. #define soclose 1e-8
  22. #define chocolate win
  23. // so much chocolate
  24. #define patkan 9
  25. #define ff first
  26. #define ss second
  27. #define abs(x) ((x < 0)?-(x):x)
  28. #define uint unsigned int
  29. #define dbl long double
  30. #define pi 3.14159265358979323846
  31. using namespace std;
  32. // mylittledoge
  33.  
  34. typedef long long cat;
  35.  
  36. #ifdef DONLINE_JUDGE
  37. // palindromic tree is better than splay tree!
  38. #define lld I64d
  39. #endif
  40.  
  41. int main() {
  42. cin.sync_with_stdio(0);
  43. cin.tie(0);
  44. cout << fixed << setprecision(10);
  45. int T;
  46. cin >> T;
  47. while(T--) {
  48. string S;
  49. int x,y;
  50. cin >> S >> x >> y;
  51. int a =0, b =0;
  52. for(int i =0; i < (int)S.length(); i++) {
  53. if(S[i] == 'a') a++;
  54. else b++;
  55. }
  56. string ans;
  57. while(a > 0 && b > 0) {
  58. if(a > b) {
  59. for(int j =0; j < min(x,a-b+1); j++) ans +='a';
  60. ans +='b';
  61. a -=min(x,a-b+1);
  62. b--;
  63. }
  64. else if(a < b) {
  65. for(int j =0; j < min(y,b-a+1); j++) ans +='b';
  66. ans +='a';
  67. b -=min(y,b-a+1);
  68. a--;
  69. }
  70. else break; // a == b
  71. }
  72. if(a > 0 && b > 0) { // a == b
  73. string s ="ab";
  74. if(!ans.empty() && ans[0] == 'b') s ="ba";
  75. for(int i =0; i < a; i++) ans +=s;
  76. cout << ans << "\n";
  77. continue;
  78. }
  79. // b == 0 || a == 0
  80. for(int i =0; i < a; i++) {
  81. if(i%x == 0 && i > 0) ans +='*';
  82. ans +='a';
  83. }
  84. for(int i =0; i < b; i++) {
  85. if(i%y == 0 && i > 0) ans +='*';
  86. ans +='b';
  87. }
  88. cout << ans << "\n";
  89. }
  90. }
  91.  
  92. // look at my code
  93. // my code is amazing
  94.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout