lalalalalalalaalalla

Untitled

Jun 30th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <math.h>
  14. #include <bitset>
  15.  
  16. #define int long long
  17. #define ull unsigned long long
  18. #define all(a) a.begin(), a.end()
  19. #define pii pair<int, int>
  20. #define pb push_back
  21.  
  22. using namespace std;
  23.  
  24. const double PI = 3.14159265358;
  25.  
  26. long long gcd(long long a, long long b) {
  27. if (a==0) return b;
  28. if (b==0) return a;
  29. if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
  30. }
  31. int prime(int p) { // 1 - простое
  32. for (int i=2;i*i<=p;i++) {
  33. if (p%i==0 && i<p) return 0;
  34. }
  35. return 1;
  36. }
  37.  
  38. double s(int x1, int y1, int x2, int y2) {
  39. return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  40. }
  41.  
  42. bool q(int x, int y) {
  43. return ((x % 2 == 0 or y % 2 == 0) and not (x % 2 == 0 and y % 2 == 0));
  44. }
  45.  
  46. signed main()
  47. {
  48. ios_base::sync_with_stdio(0);
  49. cin.tie(0);
  50. cout.tie(0);
  51. string s;
  52. getline(cin, s);
  53. int op = -1, eq = -1;
  54. bool correct = true;
  55. vector<int> m;
  56. int n = s.size();
  57. for (int i = 0; i < n; i++) {
  58. if (s[i] == '-') m.pb(i);
  59. }
  60. if (find(all(s), '-') != s.end()) op = find(all(s), '-') - s.begin();
  61. if (find(all(s), '+') != s.end()) op = find(all(s), '+') - s.begin();
  62. if (find(all(s), '*') != s.end()) op = find(all(s), '*') - s.begin();
  63. if (find(all(s), '/') != s.end()) op = find(all(s), '/') - s.begin();
  64. if (find(all(s), '=') != s.end()) eq = find(all(s), '=') - s.begin();
  65. else {correct = false;}
  66. if (op == find(all(s), '-') - s.begin() and m[0] == 0) {op = m[1];}
  67. bool negf=false, negs=false, negt=false;
  68. // cout << op << "\n" << eq << "\n";;
  69. if (op == 0 or op > eq or op + 1 == eq or eq == n - 1 or op == -1 or eq == -1) {correct = false;
  70. // cout << "false\n";
  71. }
  72. int first = 0, second = 0, third = 0;
  73. for (int i = 0; i < op; i++) {
  74. if (s[i] == '-' and i == 0) {negf = true; continue;
  75. // cout << "first\n";
  76. }
  77. if ((s[i] == '0' and i == 0 and op != i + 1) or (s[i] == '0' and i == 1 and negf == true and op != i + 1)) {
  78. correct = false;
  79. break;
  80. }
  81. if (s[i] >= '0' and s[i] <= '9') first = first * 10 + (s[i] - '0');
  82. else {correct = false;
  83. // cout << "false first\n" << s[i] << "\n";
  84. }
  85. }
  86. for (int i = op + 1; i < eq; i++) {
  87. if (s[i] == '-' and i == op + 1) {negs = true; continue;
  88. // cout << "second\n";
  89. }
  90. if ((s[i] == '0' and i == op + 1 and eq != i + 1) or (s[i] == '0' and i == op+2 and negs==true and eq != i + 1)) {
  91. correct = false;
  92. break;
  93. }
  94. if (s[i] >= '0' and s[i] <= '9') second = second * 10 + (s[i] - '0');
  95. else {correct = false;
  96. // cout << "false second\n";
  97. }
  98. }
  99. // cout << correct << "\n";
  100. for (int i = eq + 1; i < n; i++) {
  101. if (s[i] == '-' and i == eq + 1) {negt = true; continue;
  102. // cout << "third" << "\n";
  103. }
  104. if ((s[i] == '0' and i == eq + 1 and n != i + 1) or (s[i] == '0' and i == eq + 2 and negt == true and n != i + 1)) {
  105. correct = false;
  106. break;
  107. }
  108. if (s[i] >= '0' and s[i] <= '9') third = third * 10 + (s[i] - '0');
  109. else {correct = false;
  110. // cout << "false third\n";
  111. }
  112. }
  113. // cout << correct << "\n";
  114. if (first == 0 and negf == true and op == 1) correct = false;
  115. if (second == 0 and negs == true and eq - op == 2) correct = false;
  116. if (third == 0 and negt == true and n - eq == 2) correct = false;
  117. if (negf) first = -first;
  118. if (negs) second = -second;
  119. if (negt) third = -third;
  120. if (correct) {
  121. if (s[op] == '+') {
  122. if (first + second == third) cout << "YES";
  123. else cout << "NO";
  124. } else if (s[op] == '-') {
  125. if (first - second == third) cout << "YES";
  126. else cout << "NO";
  127. } else if (s[op] == '*') {
  128. if (first * second == third) cout << "YES";
  129. else cout << "NO";
  130. } else if (s[op] == '/') {
  131. if ((double)first / second == (double)third) cout << "YES";
  132. else cout << "NO";
  133. } else cout << "ERROR";
  134. } else cout << "ERROR";
  135. }
Add Comment
Please, Sign In to add comment