Advertisement
Bohdan_Chaika

Untitled

Mar 13th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define FOR(i,a,b) for(int i = (a); i < (b); i++)
  5.  
  6. #define rep(i,n) FOR(i,0,n)
  7. #define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
  8. #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
  9. #define FILL(a, value) memset(a, value, sizeof(a)
  10.  
  11. #define SZ(a) (int)a.size()
  12. #define ALL(a) a.begin(), a.end()
  13. #define PB push_back
  14. #define MP make_pair
  15.  
  16. typedef unsigned long long LL;
  17. typedef vector<int> VI;
  18. typedef vector<bool>VB;
  19. typedef pair<int, int> PII;
  20.  
  21. const double PI = acos(-1.0);
  22. const int INF = 1000 * 1000 * 1000 + 7;
  23. const LL LINF = INF * (LL)INF;
  24.  
  25. const double EPS = 1e-7;
  26. const int MAX = 20 * 1000 + 47;
  27. const int MOD = 1000 * 1000 * 1000 + 7;
  28. const int MAS = 1000 * 100;
  29.  
  30.  
  31.  
  32. int main() {
  33. ios::sync_with_stdio(false);
  34. cin.tie(0);
  35. string a,b; cin >> a >> b ;
  36. int a0 =0 , a1 =0 ;
  37. rep(i,a.size())
  38. {
  39. if(a[i] == '1')
  40. {
  41. a1++;
  42. } else
  43. {
  44. a0++;
  45. }
  46. }
  47.  
  48. int idx = 0;
  49. rep(i,b.size())
  50. {
  51. if(a1!=0 && a0!=0)
  52. {
  53. a[idx] =b[i] ;
  54. b[i ]== '0'?a0--:a1--;
  55. idx++ ;
  56.  
  57. }
  58. }
  59. int y = 0 ;
  60. FOR(i,1,b.size())
  61. {
  62. if(b[i] ==b[y] )
  63. {
  64. y++ ;
  65. } else
  66. {
  67. y = 0 ;
  68. }
  69. }
  70. while (a1 != 0 && a0 != 0) {
  71.  
  72. FOR(i,y,b.size()) {
  73. if (a1 == 0 || a0 == 0) {
  74. break;
  75. }
  76. if (b[i] == '0') {
  77.  
  78. a[idx] = '0', a0--;
  79. } else {
  80. a[idx] = '1', a1--;
  81. }
  82. idx++;
  83. }
  84.  
  85.  
  86. }
  87. while (a1 != 0) {
  88. a[idx] = '1';
  89. a1--;
  90. idx++;
  91. }
  92. while (a0 != 0) {
  93. a[idx] = '0';
  94. a0--;
  95. idx++;
  96. }
  97. cout << a;
  98.  
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement