Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int counter(char* s)
  4. {
  5. int cc = 0;
  6. while (s[cc] != '\0')
  7. {
  8. cc++;
  9. }
  10. return cc;
  11. }
  12. void summ(char* a, char* b, char* c, int max)
  13. {
  14. int i;
  15. char t;
  16. for (i = max - 1; i >= 0; i--)
  17. {
  18. if (a[i] >= 48 && a[i] < 58 && b[i] >= 48 && b[i] < 58)
  19. {
  20. c[i] = a[i] + b[i];
  21. if (c[i] == 113 || c[i] == 114)
  22. {
  23. c[i] = a[i] + b[i] - 'A';
  24. a[i - 1] = a[i - 1] + '1' - '0';
  25. }
  26. if (c[i] >= 106 && c[i] <= 112) c[i] = c[i] - ')';
  27. if (c[i] >= 96 && c[i] <= 105) c[i] = c[i] - '0';
  28. }
  29. if ((a[i] >= 65 && a[i] < 72 && b[i] >= 48 && b[i] < 58) || (b[i] >= 65 && b[i] < 72 && a[i] >= 48 && a[i] < 58))
  30. {
  31. c[i] = a[i] + b[i]-'0'-'A';
  32. if (c[i] >=0 && c[i] <=6) c[i] = c[i] + 'A';
  33.  
  34. if (c[i] >=7 && c[i] <=15)
  35. {
  36. c[i] = c[i] + ')';
  37. a[i - 1] = a[i - 1] + '1' - '0';
  38. }
  39.  
  40.  
  41. }
  42. if (a[i] >= 65 && a[i] <= 71 && b[i] >= 65 && b[i] <= 71)
  43. {
  44. c[i] = a[i] + b[i] - 'A' - 'A';
  45. if (c[i] >= 0 && c[i] <= 6)
  46. {
  47. c[i] = c[i] + '3';
  48. a[i - 1] = a[i - 1] + '1' - '0';
  49. }
  50. if (c[i] >= 7 && c[i] <= 12)
  51. {
  52. c[i] = c[i] + ':';
  53. a[i - 1] = a[i - 1] + '1' - '0';
  54. }
  55. }
  56. }
  57. c[max] = '\0';
  58. if (c[0] == '0')
  59. {
  60. for (i = 1; i < max + 1; i++)
  61. cout << c[i];
  62. }
  63. else
  64. cout << c;
  65. }
  66. void razn(char* d, char* e, char* r,int max)
  67. {
  68. int i;
  69. for (i = max - 1; i >= 0; i--)
  70. {
  71. if (d[i] >= 48 && d[i] < 58 && e[i] >= 48 && e[i] < 58)
  72. {
  73. if (d[i] >= e[i]) r[i] = (d[i] - '0') - (e[i] - '0') + '0';
  74. if (d[i] == e[i]) r[i] = '0';
  75. if (d[i] < e[i])
  76. {
  77. d[i - 1] = d[i - 1] - '1' + '0';
  78. r[i] = (d[i] - '0' + 17) - (e[i] - '0');
  79. if (r[i] > 9 && r[i] < 17) r[i] = r[i] + '7';
  80. else r[i] = r[i] + '0';
  81. }
  82. }
  83. if (d[i] >= 65 && d[i] <= 71 && e[i] >= 48 && e[i] <= 57)
  84. {
  85. r[i] = d[i] - e[i];
  86. if (r[i] >= 17 && r[i] <= 23) r[i] = r[i] + '0';
  87. if (r[i] >= 14 && r[i] <= 16) r[i] = r[i] + ')';
  88. }
  89. if ((e[i] >= 65 && e[i] <= 71 && d[i] >= 48 && d[i] <= 57))
  90. {
  91. d[i - 1] = d[i - 1] - '1' + '0';
  92. r[i] = (d[i] - '0' + 17) - (e[i] - '7');
  93. if (r[i] >= 0 && r[i] <= 9) r[i] = r[i] + '0';
  94. if (r[i] >= 10 && r[i] <= 16) r[i] = r[i] + '7';
  95. }
  96. if (d[i] >= 65 && d[i] <= 71 && e[i] >= 65 && e[i] <= 71)
  97. {
  98. if (d[i] >= e[i]) r[i] = d[i] - e[i] + '0';
  99. if (d[i] < e[i])
  100. {
  101. d[i - 1] = d[i - 1] - '1' + '0';
  102. if (d[i - 1] == 64) d[i - 1] = '9';
  103. r[i] = d[i] - e[i] + 'H';
  104. }
  105. }
  106. }
  107.  
  108. r[max] = '\0';
  109.  
  110. if (r[0] == '0')
  111. {
  112. for (i = 1; i < max; i++)
  113. cout << r[i];
  114. }
  115. else
  116. cout << '\n' << r;
  117. }
  118. char* zap(char* a, char* b, int s1, int s2)
  119. {
  120. int i, j;
  121.  
  122. for (i = s2 - 1, j = s1-1; i >= (s2 - s1), j >=0; i--, j--)
  123. {
  124. a[i] = a[j];
  125. }
  126. for (i = 0; i < (s2 - s1); i++)
  127. a[i] = '0';
  128. a[s2] = '\0';
  129. return a;
  130. }
  131. int main()
  132. {
  133. setlocale(LC_ALL, "ru");
  134. char a[20], b[20], d[20], e[20];
  135. char c[20], r[20];
  136. int i, s1, s2, max = 0, in1 = 0, in2 = 0, povt = 0,s3,s4;
  137. gets_s(a);
  138. gets_s(b);
  139. s3 = counter(a);
  140. s4 = counter(b);
  141. s1 = counter(a);
  142. s2 = counter(b);
  143. if (a[0] == '-')
  144. {
  145. in1++;
  146. for (i = 0; i < s1; i++)
  147. a[i] = a[i + 1];
  148.  
  149. }
  150. if (b[0] == '-')
  151. {
  152. in2++;
  153. for (i = 0; i < s2; i++)
  154. b[i] = b[i + 1];
  155. }
  156. for (i = s1 - 1; i >= 0; i--)
  157. {
  158. a[i + 1] = a[i];
  159.  
  160. }
  161. a[0] = '0';
  162. a[s1 + 1] = '\0';
  163. s1 = counter(a);
  164. s2 = counter(b);
  165. if (s1 < s2)
  166. {
  167. max = s2;
  168. zap(a, b, s1, s2);
  169. }
  170. if (s2 < s1)
  171. {
  172. max = s1;
  173. zap(b, a, s2, s1);
  174. }
  175. if (s1 == s2) max = s1;
  176. for (i = 0; i < max + 1; i++)
  177. {
  178. d[i] = a[i];
  179. e[i] = b[i];
  180. }
  181. s1 = counter(a);
  182. s2 = counter(b);
  183. if (s1 == s2)
  184. {
  185. for (i = 0; i < s1; i++)
  186. {
  187. if (a[i] == b[i]) povt++;
  188. }
  189. }
  190. if (a[0] != '+' && a[0] != '-' && b[0] != '+' && b[0] != '-'&& d[0] != '+' && d[0] != '-' && e[0] != '+' && e[0] != '-'&&in1==0&&in2==0)
  191. {
  192. if (s3 < s4)
  193. {
  194. cout << "summ:"; summ(b, a, c, max);
  195. }
  196. else if (s3 >= s4)
  197. {
  198. cout << "summ:"; summ(a, b, c, max);
  199. }
  200. if (s3 < s4)
  201. {
  202. cout << "\nrazn:-"; razn(e, d, r, max);
  203. }
  204. else if (s3 > s4)
  205. {
  206. cout << "\nrazn:"; razn(d, e, r, max);
  207. }
  208. else if (s3 == s4 && d[1] > e[1])
  209. {
  210. cout << "\nrazn:"; razn(d, e, r, max);
  211. }
  212. else if (s3 == s4 && d[1] < e[1])
  213. {
  214. cout << "\nrazn:-"; razn(e, d, r, max);
  215. }
  216. else if (s1 == s2 && povt == s1) cout << "\nrazn:0";
  217. else cout << "\nrazn:"; razn(d, e, r, max);
  218. }
  219. if (a[0] != '+' && a[0] != '-' && in2==1&&in1==0)
  220. {
  221.  
  222. if (s3 < s4)
  223. {
  224. cout << "\nsumm:-"; razn(e, d, r, max);
  225. }
  226. else if (s3 > s4)
  227. {
  228. cout << "\nsumm:"; razn(d, e, r, max);
  229. }
  230. else if (s3 == s4 && d[1] > e[1])
  231. {
  232. cout << "\nsumm:"; razn(d, e, r, max);
  233. }
  234. else if (s3 == s4 && d[1] < e[1])
  235. {
  236. cout << "\nsumm:-"; razn(e, d, r, max);
  237. }
  238. else if (s1 == s2 && s1 == povt) cout << "\nsumm:0";
  239. cout << "\nrazn:"; summ(a, b, c, max);
  240.  
  241. }
  242. if (b[0] != '+' && b[0] != '-' && in1 == 1&&in2==0)
  243. {
  244.  
  245. if (s3 < s4)
  246. {
  247. cout << "\nsumm:"; razn(e, d, r, max);
  248. }
  249. else if (s3 > s4)
  250. {
  251. cout << "\nsumm:-"; razn(d, e, r, max);
  252. }
  253. else if (s3 == s4 && d[1] > e[1])
  254. {
  255. cout << "\nsumm:-"; razn(d, e, r, max);
  256. }
  257. else if (s3 == s4 && d[1] < e[1])
  258. {
  259. cout << "\nsumm:"; razn(e, d, r, max);
  260. }
  261. else if (s1 == s2 && s1 == povt) cout << "\nsumm:0";
  262.  
  263. cout << "\nrazn:-"; summ(a, b, c, max);
  264. }
  265. if (in1 == 1 && in2 == 1)
  266. {
  267. cout << "summ:-"; summ(a, b, c, max);
  268.  
  269. if (s3 < s4)
  270. {
  271. cout << "\nrazn:"; razn(e, d, r, max);
  272. }
  273. else if (s3 > s4)
  274. {
  275. cout << "\nrazn:-"; razn(d, e, r, max);
  276. }
  277. else if (s3 == s4 && d[1] > e[1])
  278. {
  279. cout << "\nrazn:-"; razn(d, e, r, max);
  280. }
  281. else if (s3 == s4 && d[1] < e[1])
  282. {
  283. cout << "\nrazn:"; razn(e, d, r, max);
  284. }
  285. else if(s1==s2&&s1==povt) cout << "\nrazn:0";
  286. }
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement