fork download
  1. //This code using C++
  2. //Code is for who just starting up or already knowing a bit about C++
  3. //This code is used to add, subtract, multiply, divide large numbers like 1e100 or 1e1000
  4. //Code by @banhratlangon (Find me in Discord)
  5. //Enjoy the code :D
  6.  
  7. #include <bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. string tostring(long long n)
  12. {
  13. string s = "";
  14. while(n != 0)
  15. {
  16. s += (char) (n % 10 + 48);
  17. n /= 10;
  18. }
  19. return s;
  20. }
  21.  
  22. bool ss(string a, string b)
  23. {
  24. while(a[0] == '0') a.erase(0, 1);
  25. while(b[0] == '0') b.erase(0, 1);
  26. if(a.size() < b.size()) return true;
  27. if(a.size() > b.size()) return false;
  28. if(a < b) return true;
  29. return false;
  30. }
  31.  
  32. string cong(string a, string b)
  33. {
  34. string c = "";
  35. int nho = 0;
  36. while(a.size() < b.size()) a = '0' + a;
  37. while(a.size() > b.size()) b = '0' + b;
  38. int n = a.size();
  39. for(int i = n - 1; i >= 0; i--)
  40. {
  41. int x = a[i] + b[i] - 96 + nho;
  42. nho = x / 10;
  43. x %= 10;
  44. c = (char) (x + '0') + c;
  45. }
  46. if(nho > 0) c = '1' + c;
  47. return c;
  48. }
  49.  
  50. string tru(string a, string b)
  51. {
  52. bool am = false;
  53. string c = "";
  54. int nho = 0;
  55. if(ss(a, b))
  56. {
  57. string d = a;
  58. a = b;
  59. b = d;
  60. am = true;
  61. }
  62. while(a.size() > b.size()) b = '0' + b;
  63. int n = a.size();
  64. for(int i = n - 1; i >= 0; i--)
  65. {
  66. int x = a[i] - b[i] - nho;
  67. if(x < 0)
  68. {
  69. x += 10;
  70. nho = 1;
  71. }
  72. else nho = 0;
  73. c = (char) (x + '0') + c;
  74. }
  75. while(c[0] == '0') c.erase(0, 1);
  76. if(am) c = '-' + c;
  77. return c;
  78. }
  79.  
  80. string nhan1cs(string a, int b)
  81. {
  82. string c = "";
  83. int n = a.size(), nho = 0;
  84. for(int i = n - 1; i >= 0; i--)
  85. {
  86. int x = (a[i] - 48) * b + nho;
  87. nho = x / 10;
  88. x %= 10;
  89. c = (char) (x + 48) + c;
  90. }
  91. if(nho > 0) c = (char)(nho + 48) + c;
  92. return c;
  93. }
  94.  
  95. string nhan(string a, string b)
  96. {
  97. string c = "";
  98. int n = b.size(), hang = 0;
  99. for(int i = n - 1; i >= 0; i--)
  100. {
  101. string x = nhan1cs(a, b[i] - 48);
  102. hang++;
  103. for(int i = 0; i < hang; i++) x += '0';
  104. c = cong(c, x);
  105. }
  106. c.erase(c.size() - 1, 1);
  107. return c;
  108. }
  109.  
  110. string chia(string a, long long b)
  111. {
  112. string c = "";
  113. int n = a.size(), x;
  114. long long so = 0;
  115. for(int i = 0; i < n; i++)
  116. {
  117. so = 10 * so + (a[i] - 48);
  118. x = so / b;
  119. so %= b;
  120. c += (char) (x + 48);
  121. }
  122. while(c[0] == '0') c.erase(0, 1);
  123. return c;
  124. }
  125.  
  126.  
  127.  
  128. int main()
  129. {
  130. long long d;
  131. string a, b;
  132. cout << "Remember that if you use devide or modulo, the second number\n";
  133. cout << "input must be under or equal to 1e18.\n";
  134. cout << "Type + or - or * or / or % to start caculation (% is modulo).\n";
  135. char cha;
  136. cin >> cha;
  137. if(cha != '+' && cha != '-' && cha != '*' && cha != '/' && cha != '%')
  138. {
  139. cout << "Try again.\n";
  140. return 0;
  141. }
  142. if(cha == '+')
  143. {
  144. cin >> a >> b;
  145. cout << cong(a, b);
  146. }
  147. else if(cha == '-')
  148. {
  149. cin >> a >> b;
  150. cout << tru(a, b);
  151. }
  152. else if(cha == '*')
  153. {
  154. cin >> a >> b;
  155. cout << nhan(a, b);
  156. }
  157. else if(cha == '/')
  158. {
  159. cin >> a >> d;
  160. cout << chia(a, d);
  161. }
  162. else
  163. {
  164. cin >> a >> d;
  165. string g = tostring(d);
  166. cout << tru(a, nhan(chia(a, d), g));
  167. }
  168. }
  169.  
Success #stdin #stdout 0.01s 5324KB
stdin
-
1234
4321
stdout
Remember that if you use devide or modulo, the second number
input must be under or equal to 1e18.
Type + or - or * or / or % to start caculation (% is modulo).
-3087