fork(1) download
  1. #include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<vector>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. char total[102],more[102];
  10. vector<int> tot,mor,kl;
  11. int q=0;
  12.  
  13. while(q<10)
  14. {
  15. cin>>total>>more;
  16.  
  17. int t=strlen(total);
  18. int m=strlen(more);
  19.  
  20. for(int i=t-1;i>-1;i--)
  21. tot.push_back(total[i]-'0');
  22.  
  23. for(int i=m-1;i>-1;i--)
  24. mor.push_back(more[i]-'0');
  25.  
  26. int carry=0,temp=0;
  27. for(int i=0;i<t;i++)
  28. {
  29. if(i<=m)
  30. mor.push_back(0);
  31.  
  32. temp=tot[i]+mor[i]+carry;
  33.  
  34. if(temp>9)
  35. carry=1;
  36. else carry=0;
  37.  
  38. kl.push_back(temp%10);
  39. }
  40.  
  41. if(carry) kl.push_back(1);
  42. reverse(kl.begin(),kl.end()); //double the result int right manner
  43.  
  44. vector<int>::iterator it;
  45. vector<int> klaudia;
  46.  
  47. temp=0;
  48. for(it=kl.begin();it!=kl.end();it++)
  49. {
  50. temp=temp*10+(*it);
  51. if((temp%2)!=0)
  52. {
  53. if(temp>2)
  54. {
  55. klaudia.push_back(temp/2);
  56. temp=temp%2;
  57. }
  58. }
  59. else
  60. {
  61. klaudia.push_back(temp/2);
  62. temp=0;
  63. }
  64. }
  65.  
  66. for(it=klaudia.begin();it!=klaudia.end();it++)
  67. cout<<*it;
  68. cout<<endl;
  69.  
  70. reverse(klaudia.begin(),klaudia.end());
  71.  
  72. int b=0;
  73. temp=0;
  74. vector<int> res;
  75.  
  76.  
  77. for(int i=0;i<t;i++)
  78. {
  79. tot[i]=tot[i]-b;
  80. b=0;
  81.  
  82. //if(klaudia.size()+1<=i)
  83. //klaudia.push_back(0);
  84.  
  85. temp=tot[i]-klaudia[i];
  86. //cout<<"#"<<tot[i]<<"#"<<klaudia[i]<<"*"<<temp<<endl;
  87. if(temp<0)
  88. {
  89. b=1;
  90. res.push_back((10+tot[i])-klaudia[i]);
  91. //cout<<(10+tot[i])-klaudia[i]<<"***"<<endl;
  92.  
  93. }
  94. else
  95. {
  96. res.push_back(temp);
  97. // cout<<temp<<"**"<<endl;
  98. }
  99.  
  100. }
  101. reverse(res.begin(),res.end());
  102.  
  103. int flag=0;
  104. for(it=res.begin();it!=res.end();it++)
  105. {
  106. if(!(*it) && flag==0)
  107. continue;
  108. cout<<*it;
  109. flag=1;
  110. }
  111. flag=0;
  112. for(it=res.begin();it!=res.end();it++)
  113. {
  114. if(!(*it))
  115. flag=1;
  116. else
  117. {
  118. flag=0;
  119. break;
  120. }
  121. }
  122. if(flag)
  123. cout<<0;
  124.  
  125. cout<<endl;
  126. q++;
  127.  
  128. }
  129. }
Success #stdin #stdout 0s 3476KB
stdin
10
2
999999999999
99
stdout
6
4
5015000494511
984999505389
5049500494-46104945000150
895054999640
50495004934650150004945116-1445004950
8310554994740
5049500488-45049500494-461049450001506-1145004950
4932054993640
50495004824650495004934650150004945116-14450049506-2395004950
9311604992540
5049500477-45049500488-45049500494-461049450001506-11450049506-2245004950
4933154991440
50495004714650495004824650495004934650150004945116-14450049506-23950049506-3295004950
9312704990340
5049500466-45049500477-45049500488-45049500494-461049450001506-11450049506-22450049506-3345004950
4934254989240
5049500414650495004714650495004824650495004934650150004945116-14450049506-23950049506-32950049506-4195004950
9313804978140