Advertisement
lalalalalalalaalalla

Untitled

Jun 30th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 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. int fibonacci(int q) {
  43. if (q <= 0) return 0;
  44. if (q < 3) return 1;
  45. return fibonacci(q - 1) + fibonacci(q - 2);
  46. }
  47.  
  48. bool q(int x, int y) {
  49. return ((x % 2 == 0 or y % 2 == 0) and not (x % 2 == 0 and y % 2 == 0));
  50. }
  51.  
  52. signed main()
  53. {
  54. ios_base::sync_with_stdio(0);
  55. cin.tie(0);
  56. cout.tie(0);
  57. string s;
  58. cin >> s;
  59. int op = -1, eq = -1;
  60. bool correct = true;
  61. vector<int> m;
  62. int n = s.size();
  63. for (int i = 0; i < n; i++) {
  64. if (s[i] == '-') m.pb(i);
  65. }
  66. if (find(all(s), '-') != s.end()) op = find(all(s), '-') - s.begin();
  67. if (find(all(s), '+') != s.end()) op = find(all(s), '+') - s.begin();
  68. if (find(all(s), '*') != s.end()) op = find(all(s), '*') - s.begin();
  69. if (find(all(s), '/') != s.end()) op = find(all(s), '/') - s.begin();
  70. if (find(all(s), '=') != s.end()) eq = find(all(s), '=') - s.begin();
  71. else {correct = false;}
  72. if (op == find(all(s), '-') - s.begin() and m[0] == 0) {op = m[1];}
  73. bool negf=false, negs=false, negt=false;
  74. // cout << op << "\n" << eq << "\n";;
  75. if (op == 0 or op > eq or op + 1 == eq or eq == n - 1 or op == -1 or eq == -1) {correct = false;
  76. // cout << "false\n";
  77. }
  78. int first = 0, second = 0, third = 0;
  79. for (int i = 0; i < op; i++) {
  80. if (s[i] == '-' and i == 0) {negf = true; continue;
  81. // cout << "first\n";
  82. }
  83. if (s[i] >= '0' and s[i] <= '9') first = first * 10 + (s[i] - '0');
  84. else {correct = false;
  85. // cout << "false first\n" << s[i] << "\n";
  86. }
  87. }
  88. for (int i = op + 1; i < eq; i++) {
  89. if (s[i] == '-' and i == op + 1) {negs = true; continue;
  90. // cout << "second\n";
  91. }
  92. if (s[i] >= '0' and s[i] <= '9') second = second * 10 + (s[i] - '0');
  93. else {correct = false;
  94. // cout << "false second\n";
  95. }
  96. }
  97. for (int i = eq + 1; i < n; i++) {
  98. if (s[i] == '-' and i == eq + 1) {negt = true; continue;
  99. // cout << "third" << "\n";
  100. }
  101. if (s[i] >= '0' and s[i] <= '9') third = third * 10 + (s[i] - '0');
  102. else {correct = false;
  103. // cout << "false third\n";
  104. }
  105. }
  106. if (negf) first = -first;
  107. if (negs) second = -second;
  108. if (negt) third = -third;
  109. if (correct) {
  110. if (s[op] == '+') {
  111. if (first + second == third) cout << "YES";
  112. else cout << "NO";
  113. } else if (s[op] == '-') {
  114. if (first - second == third) cout << "YES";
  115. else cout << "NO";
  116. } else if (s[op] == '*') {
  117. if (first * second == third) cout << "YES";
  118. else cout << "NO";
  119. } else if (s[op] == '/') {
  120. if ((double)first / second == (double)third) cout << "YES";
  121. else cout << "NO";
  122. } else cout << "ERROR";
  123. } else cout << "ERROR";
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement