SHARE
TWEET

Untitled

lalalalalalalaalalla Jun 30th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     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 s[i] <= '9') first = first * 10 + (s[i] - '0');
  78.         else {correct = false;
  79. //         cout << "false first\n" << s[i] << "\n";
  80.         }
  81.     }
  82.     for (int i = op + 1; i < eq; i++) {
  83.         if (s[i] == '-' and i == op + 1) {negs = true; continue;
  84. //         cout << "second\n";
  85.          }
  86.         if (s[i] >= '0' and s[i] <= '9') second = second * 10 + (s[i] - '0');
  87.         else {correct = false;
  88. //         cout << "false second\n";
  89.          }
  90.     }
  91.     for (int i = eq + 1; i < n; i++) {
  92.         if (s[i] == '-' and i == eq + 1) {negt = true; continue;
  93. //         cout << "third" << "\n";
  94.          }
  95.         if (s[i] >= '0' and s[i] <= '9') third = third * 10 + (s[i] - '0');
  96.         else {correct = false;
  97. //         cout << "false third\n";
  98.          }
  99.     }
  100.     if (negf) first = -first;
  101.     if (negs) second = -second;
  102.     if (negt) third = -third;
  103.     if (correct) {
  104.         if (s[op] == '+') {
  105.             if (first + second == third) cout << "YES";
  106.             else cout << "NO";
  107.         } else if (s[op] == '-') {
  108.             if (first - second == third) cout << "YES";
  109.             else cout << "NO";
  110.         } else if (s[op] == '*') {
  111.             if (first * second == third) cout << "YES";
  112.             else cout << "NO";
  113.         } else if (s[op] == '/') {
  114.             if ((double)first / second == (double)third) cout << "YES";
  115.             else cout << "NO";
  116.         } else cout << "ERROR";
  117.     } else cout << "ERROR";
  118. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top