fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. void wypelnij( int t[10000], int rozmiar )
  6. {
  7. for (int i=0;i<10000;i++){
  8. if (i<rozmiar) cin>> t[i];
  9. else t[i]=0;}
  10. }
  11.  
  12. int main()
  13. {
  14. int d;
  15. cin>>d;
  16. for(int j=0;j<d;j++){
  17. short int n,m,maks;
  18. cin>> n;
  19. int a[10000];
  20. wypelnij(a,n);
  21. cin>> m;
  22. int b[10000];
  23. wypelnij(b,m);
  24. reverse(a,a+n);
  25. reverse(b,b+m);
  26. maks=max(n,m);
  27. /*for (int i=0;i<100;i++) cout<< a[i]<<" ";
  28.   cout<<endl;
  29.   for (int i=0;i<100;i++) cout<< b[i]<<" ";*/
  30. int wynik[maks];
  31. int reszta = 0;
  32. for (int i=0;i<maks;i++){
  33. wynik[i] = (a[i] + b[i] + reszta) % 2;
  34. reszta = (a[i] + b[i] + reszta) / 2;
  35.  
  36. if (reszta > 0) wynik[i+1] = reszta;
  37. }
  38. reverse(wynik,wynik+maks);
  39. if (reszta > 0) cout<<"1";
  40. for (int i=0;i<maks;i++) cout<< wynik[i];
  41. }
  42. }
  43.  
Success #stdin #stdout 0s 15232KB
stdin
6
4 
1 0 0 1
2
1 1
4
1 1 1 1
6
1 1 1 1 1 1
1
0
40
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
1
0
20
1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1
1
20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1
0
stdout
1100100111011111111111111111110111111111111111111101011111111111111110110000000000000000000011111111111111111111