Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define FOR(i,a,b) for(int i = (a); i < (b); i++)
- #define rep(i,n) FOR(i,0,n)
- #define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
- #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
- #define FILL(a, value) memset(a, value, sizeof(a)
- #define SZ(a) (int)a.size()
- #define ALL(a) a.begin(), a.end()
- #define PB push_back
- #define MP make_pair
- typedef unsigned long long LL;
- typedef vector<int> VI;
- typedef vector<bool>VB;
- typedef pair<int, int> PII;
- const double PI = acos(-1.0);
- const int INF = 1000 * 1000 * 1000 + 7;
- const LL LINF = INF * (LL)INF;
- const double EPS = 1e-7;
- const int MAX = 20 * 1000 + 47;
- const int MOD = 1000 * 1000 * 1000 + 7;
- const int MAS = 1000 * 100;
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- string a,b; cin >> a >> b ;
- int a0 =0 , a1 =0 ;
- rep(i,a.size())
- {
- if(a[i] == '1')
- {
- a1++;
- } else
- {
- a0++;
- }
- }
- int idx = 0;
- rep(i,b.size())
- {
- if(a1!=0 && a0!=0)
- {
- a[idx] =b[i] ;
- b[i ]== '0'?a0--:a1--;
- idx++ ;
- }
- }
- int y = 0 ;
- FOR(i,1,b.size())
- {
- if(b[i] ==b[y] )
- {
- y++ ;
- } else
- {
- y = 0 ;
- }
- }
- while (a1 != 0 && a0 != 0) {
- FOR(i,y,b.size()) {
- if (a1 == 0 || a0 == 0) {
- break;
- }
- if (b[i] == '0') {
- a[idx] = '0', a0--;
- } else {
- a[idx] = '1', a1--;
- }
- idx++;
- }
- }
- while (a1 != 0) {
- a[idx] = '1';
- a1--;
- idx++;
- }
- while (a0 != 0) {
- a[idx] = '0';
- a0--;
- idx++;
- }
- cout << a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement