fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. template<typename F, typename S>
  5. ostream &operator<<(ostream &os, const pair<F, S> &p) {
  6. return os << "(" << p.first << ", " << p.second << ")";
  7. }
  8.  
  9. template<typename T>
  10. ostream &operator<<(ostream &os, const vector<T> &v) {
  11. os << "{";
  12. typename vector<T>::const_iterator it;
  13. for (it = v.begin(); it != v.end(); it++) {
  14. if (it != v.begin()) os << ", ";
  15. os << *it;
  16. }
  17. return os << "}";
  18. }
  19.  
  20. template<typename T>
  21. ostream &operator<<(ostream &os, const set<T> &v) {
  22. os << "[";
  23. typename set<T>::const_iterator it;
  24. for (it = v.begin(); it != v.end(); it++) {
  25. if (it != v.begin()) os << ", ";
  26. os << *it;
  27. }
  28. return os << "]";
  29. }
  30.  
  31. template<typename F, typename S>
  32. ostream &operator<<(ostream &os, const map<F, S> &v) {
  33. os << "[";
  34. typename map<F, S>::const_iterator it;
  35. for (it = v.begin(); it != v.end(); it++) {
  36. if (it != v.begin()) os << ", ";
  37. os << it->first << " = " << it->second;
  38. }
  39. return os << "]";
  40. }
  41.  
  42. #define debug(x) cerr << #x << " = " << x << endl;
  43. #define trace1(x) cerr<<#x<<": "<<x<<endl
  44. #define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  45. #define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  46. #define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  47. #define trace5(a, b, c, d, e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  48. #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  49.  
  50.  
  51. typedef long long int ll;
  52. typedef long double ld;
  53. typedef vector<int> vi;
  54. typedef vector<long long int> vll;
  55. typedef pair<int, int> pii;
  56. typedef pair<long long int, long long int> pll;
  57. typedef map<int, int> mii;
  58. typedef vector< pair<int, int> > vpii;
  59.  
  60. #define endl "\n";
  61. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  62. #define pb push_back
  63. #define mp make_pair
  64. #define all(c) (c).begin(),(c).end()
  65. #define tr(cont, it) for(decltype((cont).begin()) it = (cont).begin(); it != (cont).end(); it++)
  66. #define present(c, x) ((c).find(x) != (c).end())
  67. #define cpresent(c, x) (find(all(c),x) != (c).end())
  68. #define F first
  69. #define S second
  70.  
  71.  
  72. const ld PI=acos(-1.0);
  73. const ll mod = 1000000007;
  74. const ll inf = (ll) 1e15;
  75.  
  76. ll power(ll a, ll b, ll m = mod) {if (b == 0) return 1; if (b == 1) return (a % m); ll x = power(a, b / 2, m); x = (x * x) % m; if (b % 2) x = (x * a) % m;return x;}
  77. ll max(ll a, ll b) { return (a > b ? a : b); }
  78. ll min(ll a, ll b) { return (a < b ? a : b); }
  79.  
  80. const int N=1e5+5;
  81. const int M=1e5+5;
  82.  
  83. void solve() {
  84.  
  85. int a1[11]={0},a2[11]={0},a3[11]={0};
  86. int c1=0,c2=0,c3=0;
  87. string s1,s2,s3;
  88. cin >> s1 >> s2 >> s3;
  89. for(int i=0;i<10;i++)
  90. {
  91. if(s1[i]=='1')
  92. c1++;
  93. if(s2[i]=='1')
  94. c2++;
  95. if(s3[i]=='1')
  96. c3++;
  97. }
  98. set<int> s;
  99. for(int i=1;i<=c1;i++)
  100. {
  101. a1[i]=1;
  102. s.insert(i);
  103. }
  104. bool used1[11]={false};
  105. for(int i=c1+1;c2>0&&i<=10;i++)
  106. {
  107. used1[i]=true;
  108. a2[i]=1;
  109. s.insert(i);
  110. c2--;
  111. }
  112. if(c2>0)
  113. {
  114. while(c2>0)
  115. {
  116. int torem=-1;
  117. for(auto it : s)
  118. {
  119. if(used1[it]== false)
  120. torem=it;
  121. }
  122. s.erase(torem);
  123. used1[torem]=true;
  124. c2--;
  125. }
  126. }
  127.  
  128. assert(c2==0);
  129.  
  130. bool used[11]={false};
  131. for(int i=1;c3>0&&i<=10;i++)
  132. {
  133. if(s.find(i)!=s.end())
  134. continue;
  135. used[i]=true;
  136. s.insert(i);
  137. c3--;
  138. }
  139. if(c3>0)
  140. {
  141. while(c3>0)
  142. {
  143. int torem=-1;
  144. for(auto it : s)
  145. {
  146. if(used[it]== false)
  147. torem=it;
  148. }
  149. s.erase(torem);
  150. used[torem]=true;
  151. c3--;
  152. }
  153. }
  154.  
  155. assert(c3==0);
  156.  
  157. // debug(s);
  158. string ans="";
  159. for(int i=1;i<=10;i++)
  160. {
  161. int p=0;
  162. if(s.find(i)!=s.end())
  163. p=1;
  164. ans+=(char)(p+'0');
  165. }
  166. sort(ans.begin(),ans.end());
  167. reverse(ans.begin(),ans.end());
  168. cout << ans << endl;
  169.  
  170. }
  171.  
  172. int main() {
  173. IOS;
  174. int t = 1, num = 1; ///// change this t for number of testcase globally
  175. cin >> t;
  176. while (t--) {
  177. solve();
  178. }
  179. return 0;
  180. }
  181.  
  182.  
Success #stdin #stdout 0s 15240KB
stdin
2
0000101011
0001010101
0010010000
1000000010
0001000100
1001000000
stdout
1111111111
1111110000