fork(2) download
  1. #include<bits/stdc++.h>
  2. //#include<conio.h>
  3. //#define s(x) scanf("%d",&(x))
  4. #define print(x) printf("%d ",x)
  5. #define printnl(x) printf("%d\n",x);
  6. #define fi(i,a,b) for(int i=(a);i<(b);i++)
  7. #define forD(i,a,b) for(int i=(a);i>(b);--i)
  8. #define MOD 1000000009
  9. #define INF_LONG 8999999999999999999
  10. #define llu long long unsigned
  11. #define FOUND 1
  12. #define NOTFOUND 0
  13. #define MAXSIZE 10000
  14. #define pb push_back
  15. using namespace::std;
  16.  
  17. typedef vector <int> vi;
  18. typedef vector<vi> vvi;
  19. typedef pair < int, int > ii;
  20. typedef vector < ii > vii;
  21. typedef vector <vii> vvii;
  22. //int getch()
  23. //{
  24. //
  25. //}
  26. int main()
  27. {
  28. int t = 10, i = 0, j = 0, k = 0;
  29. char c;
  30. while(t-- >= 1)
  31. {
  32. i = 0, j = 0, k = 0;
  33. vi s(101, 0);
  34. vi d(101, 0);
  35. //p = s+d ; q = s-q
  36. vi p;
  37. vi q;
  38.  
  39. while((c = getch()) != 13)
  40. s[i++] = c - 48;
  41.  
  42. while((c = getch()) != 13)
  43. d[j++] = c - 48;
  44.  
  45. int ssize = i--; // i = # elements in s -1
  46. int dsize = j--; // j = # elements in d -1
  47. // cout<<"\n total apples are :\t";
  48. // for(int x = 0 ; x <= i ; ++x)
  49. // cout<<s[x];
  50. // cout<<endl;
  51. // cout<<"\n difference of apples is :\t";
  52. // for(int x = 0 ; x <= j ; ++x)
  53. // cout<<d[x];
  54. // cout<<endl;
  55.  
  56. // s + d = 2P
  57. p = vi(ssize+1, 0);
  58. q = vi(ssize, 0);
  59. for(i; i >=0 && j>=0 ; --i, --j)
  60. {
  61. p[i+1] = (s[i] + d[j] + k) %10;
  62. k = (s[i] + d[j] + k)/10;
  63. }
  64. while(i >= 0)
  65. {
  66. p[i+1] = (s[i] + k)%10;
  67. k = (s[i--] + k)/10;
  68. }
  69. p[i+1] = k;
  70. /**now 2p stands created, lets halve it 2 find # apples a has**/
  71. for(i = 0; i < p.size(); i++)
  72. {
  73. if(p[i]%2) p[i+1] += 10;
  74. p[i] /= 2;
  75. }
  76. /**lets create q**/
  77. for(i = ssize -1, j = dsize-1 ; i >=0 && j >=0 ; i--, j--)
  78. {/**#############$@@@@@@@@@@@@@@!!@@@##$$$$$$$$$**/
  79. if(s[i] >= d[j]) q[i] = s[i] - d[j];
  80. else {
  81. q[i] = s[i] - d[j] +10;
  82. s[i-1] -= 1;
  83. }
  84. }
  85. while(i >= 0)
  86. {
  87. if(s[i] >=0)
  88. q[i] = s[i];
  89. else
  90. {
  91. q[i] = 0;
  92. s[i-1] -=1;
  93. }
  94. i--;
  95. }
  96. /**now 2q stands created, lets halve it 2 find # apples a has**/
  97. for(i = 0; i < q.size(); i++)
  98. {
  99. if(q[i]%2) q[i+1] += 10;
  100. q[i] /= 2;
  101. }
  102. //for(auto it : p)
  103. // cout<<it;cout<<endl;
  104. //for(auto it : q)cout<<it;
  105. int flag = 0;
  106. i = 0;
  107. //lets print # apples a has
  108. // cout<<"\n # apples with a :\t";
  109. while(i <p.size() && p[i] == 0) ++i;
  110. while(i <p.size())
  111. {
  112. cout<<p[i++];
  113. flag = 1;
  114. }
  115. if(!flag) cout<<"0";
  116. cout<<endl;
  117.  
  118. flag =0;
  119. j = 0;
  120. // cout<<"\n # apples with b :\t";
  121. while(j < q.size() && q[j] == 0) ++j;
  122.  
  123. while(j < q.size())
  124. {
  125. cout<<q[j++];
  126. flag = 1;
  127. }
  128. if(!flag) cout<<"0";
  129. cout<<endl;
  130. }
  131. return 0;
  132. }
  133.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
10
2
100
96
1000000000000000000000000000000000000000
24000000000000000000000000000000000000
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:39:22: error: ‘getch’ was not declared in this scope
     while((c = getch()) != 13)
                      ^
prog.cpp:42:22: error: ‘getch’ was not declared in this scope
     while((c = getch()) != 13)
                      ^
prog.cpp:59:10: warning: statement has no effect [-Wunused-value]
     for(i; i >=0 && j>=0 ; --i, --j)
          ^
prog.cpp:71:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i = 0; i < p.size(); i++)
                           ^
prog.cpp:97:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i = 0; i < q.size(); i++)
                           ^
prog.cpp:109:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(i <p.size() && p[i] == 0)    ++i;
                     ^
prog.cpp:110:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(i <p.size())
                     ^
prog.cpp:121:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(j < q.size() && q[j] == 0)    ++j;
                      ^
prog.cpp:123:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(j < q.size())
                     ^
stdout
Standard output is empty