Guest User

Untitled

a guest
Jan 14th, 2020
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.  
  8. char input[300];
  9.  
  10.  
  11. cin.getline(input, 300);
  12. char firstNumber[100];
  13. int a = 2;
  14. while (input[a]!=' ')
  15. {
  16. firstNumber[a - 2] = input[a];
  17. a++;
  18. }
  19. int b = 0;
  20. firstNumber[a-2] = '\0';
  21. char secondNumber[100];
  22. while (input[a] != '\0')
  23. {
  24. secondNumber[b] = input[a];
  25. b++;
  26. a++;
  27. }
  28. secondNumber[b] = '\0';
  29.  
  30.  
  31. int counter1 = 0;
  32. while (firstNumber[counter1] != '\0')
  33. {
  34. counter1++;
  35. }
  36.  
  37. int counter2 = 0;
  38. while (secondNumber[counter2] != '\0')
  39. {
  40. counter2++;
  41. }
  42.  
  43. int arr1[100];
  44. int arr2[100];
  45. for (int i = 0; i < 100; i++)
  46. {
  47. arr1[i] = 0;
  48. arr2[i] = 0;
  49. }
  50. for (int i = 0; i < counter1; i++)
  51. {
  52. arr1[99 - i] = firstNumber[counter1 - i - 1] - '0';
  53. }
  54. for (int i = 0; i < counter2; i++)
  55. {
  56. arr2[99 - i] = secondNumber[counter2 - i - 1] - '0';
  57. }
  58.  
  59. char operation=input[0];
  60.  
  61. int result[300];
  62. for (int i = 0; i < 300; i++)
  63. {
  64. result[i] = 0;
  65.  
  66. }
  67.  
  68. if (operation == '+') {
  69. int max = 0;
  70. if (counter1 > counter2)
  71. {
  72. max = counter1;
  73. }
  74. else
  75. {
  76. max = counter2;
  77. }
  78. int temp = 0;
  79. int i = 99;
  80. for (; i > 99 - max; i--)
  81. {
  82. int a = arr1[i] + arr2[i] + temp;
  83. temp = a / 10;
  84. result[i] = a % 10;
  85. }
  86. if (temp != 0)
  87. {
  88. result[i] = temp;
  89. }
  90. }
  91. else if (operation == '-')
  92. {
  93. if (counter1 == counter1)
  94. {
  95. int temp = 0;
  96. int i = 99;
  97. for (; i > 99 - counter1; i--)
  98. {
  99. if ((arr1[i] - arr2[i]) < 0)
  100. {
  101. int tempI = i - 1;
  102. if (arr1[tempI] == 0)
  103. {
  104. while (arr1[i] == 0)
  105. {
  106. i--;
  107. }
  108. arr1[tempI]--;
  109. while (i - 1 != tempI)
  110. {
  111. tempI++;
  112. arr1[tempI] = 9;
  113. }
  114. result[i] = arr1[i] + 10 - arr2[i];
  115. }
  116. else
  117. {
  118. arr1[tempI]--;
  119. result[i] = arr1[i] + 10 - arr2[i];
  120. }
  121.  
  122. }
  123. else
  124. {
  125. result[i] = arr1[i] - arr2[i];
  126. }
  127.  
  128. }
  129.  
  130. }
  131. else if (counter1 > counter2)
  132. {
  133. int temp = 0;
  134. int i = 99;
  135. for (; i > 99 - counter1; i--)
  136. {
  137. if (true)
  138. {
  139. if ((arr1[i] - arr2[i]) < 0)
  140. {
  141.  
  142.  
  143. int tempI = i - 1;
  144. if (arr1[tempI] == 0)
  145. {
  146. while (arr1[i] == 0)
  147. {
  148. i--;
  149. }
  150. arr1[tempI]--;
  151. while (i - 1 != tempI)
  152. {
  153. tempI++;
  154. arr1[tempI] = 9;
  155. }
  156. result[i] = arr1[i] + 10 - arr2[i];
  157. }
  158. else
  159. {
  160. arr1[tempI]--;
  161. result[i] = arr1[i] + 10 - arr2[i];
  162. }
  163.  
  164. }
  165. else
  166. {
  167. result[i] = arr1[i] - arr2[i];
  168. }
  169. }
  170. else
  171. {
  172. result[i] = arr1[i];
  173. }
  174. }
  175.  
  176. }
  177. else
  178. {
  179. int temp = 0;
  180. int i = 99;
  181. for (; i > 99 - counter2; i--)
  182. {
  183. if (true)
  184. {
  185. if ((arr2[i] - arr1[i]) < 0)
  186. {
  187.  
  188.  
  189. int tempI = i - 1;
  190. if (arr2[tempI] == 0)
  191. {
  192. while (arr2[i] == 0)
  193. {
  194. i--;
  195. }
  196. arr2[tempI]--;
  197. while (i - 1 != tempI)
  198. {
  199. tempI++;
  200. arr2[tempI] = 9;
  201. }
  202. result[i] = arr2[i] + 10 - arr1[i];
  203. }
  204. else
  205. {
  206. arr2[tempI]--;
  207. result[i] = arr2[i] + 10 - arr1[i];
  208. }
  209.  
  210. }
  211. else
  212. {
  213. result[i] = arr2[i] - arr1[i];
  214. }
  215. }
  216. else
  217. {
  218. result[i] = arr2[i];
  219. }
  220. }
  221.  
  222. }
  223.  
  224.  
  225. }
  226. else if (operation == '*')
  227. {
  228. int max = 0;
  229. int min = 0;
  230. int biggerOne = 0;
  231. if (counter1 > counter2)
  232. {
  233. max = counter1;
  234. min = counter2;
  235. biggerOne = 1;
  236. }
  237. else
  238. {
  239. min = counter1;
  240. max = counter2;
  241. biggerOne = 2;
  242. }
  243. int temp = 0;
  244.  
  245. int tempArr2[300];
  246. int tempArr1[300];
  247. for (int i = 0; i < 300; i++)
  248. {
  249. tempArr1[i] = 0;
  250.  
  251. }
  252. int i = 99;
  253. for (; i > 99 - max; i--)
  254. {
  255. for (int i = 0; i < 300; i++)
  256. {
  257. tempArr2[i] = 0;
  258.  
  259. }
  260.  
  261. if (biggerOne==1)
  262. {
  263. for (int j = 299; j > 299-(i-99); j--)
  264. {
  265. tempArr2[j] = 0;
  266. }
  267. int j = 299;
  268. for (; j > 299-min; j--)
  269. {
  270. int a = arr1[i] * arr2[j-200] + temp;
  271. temp = a / 10;
  272. tempArr2[j-(99-i)] = a % 10;
  273. }
  274. if (temp!=0)
  275. {
  276. tempArr2[j - (99 - i)]=temp;
  277. }
  278. }
  279. else
  280. {
  281. for (int j = 99; j < i - 99; j++)
  282. {
  283. tempArr2[j] = 0;
  284. }
  285. for (int j = 99 - min; j < 99; j++)
  286. {
  287. int a = arr1[i] * arr2[j] + temp;
  288. temp = a / 10;
  289. tempArr2[j + i] = a % 10;
  290. }
  291.  
  292. }
  293.  
  294.  
  295.  
  296. for (int i = 0; i < 300; i++)
  297. {
  298. tempArr1[i] = result[i];
  299.  
  300. }
  301. int tempN = 0;
  302. for (int i=299; i > 0; i--)
  303. {
  304. int a = tempArr1[i] + tempArr2[i] + tempN;
  305. tempN = a / 10;
  306. result[i] = a % 10;
  307. }
  308.  
  309.  
  310. }
  311. }
  312. for (int i = 0; i < 300; i++)
  313. {
  314. if (result[i] >= 0 && result[i] <= 9)
  315. {
  316. cout << result[i];
  317. }
  318. }
  319.  
  320. system("pause");
  321. return 0;
  322. }
RAW Paste Data