Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <iomanip>
- #include <queue>
- #include <cmath>
- #include <algorithm>
- #include <tuple>
- #include <iomanip>
- #include <stdio.h>
- #include <numeric>
- #include <map>
- #include <math.h>
- #include <bitset>
- #define int long long
- #define ull unsigned long long
- #define all(a) a.begin(), a.end()
- #define pii pair<int, int>
- #define pb push_back
- using namespace std;
- const double PI = 3.14159265358;
- long long gcd(long long a, long long b) {
- if (a==0) return b;
- if (b==0) return a;
- if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
- }
- int prime(int p) { // 1 - простое
- for (int i=2;i*i<=p;i++) {
- if (p%i==0 && i<p) return 0;
- }
- return 1;
- }
- double s(int x1, int y1, int x2, int y2) {
- return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
- }
- bool q(int x, int y) {
- return ((x % 2 == 0 or y % 2 == 0) and not (x % 2 == 0 and y % 2 == 0));
- }
- signed main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string s;
- cin >> s;
- int op = -1, eq = -1;
- bool correct = true;
- vector<int> m;
- int n = s.size();
- for (int i = 0; i < n; i++) {
- if (s[i] == '-') m.pb(i);
- }
- if (find(all(s), '-') != s.end()) op = find(all(s), '-') - s.begin();
- if (find(all(s), '+') != s.end()) op = find(all(s), '+') - s.begin();
- if (find(all(s), '*') != s.end()) op = find(all(s), '*') - s.begin();
- if (find(all(s), '/') != s.end()) op = find(all(s), '/') - s.begin();
- if (find(all(s), '=') != s.end()) eq = find(all(s), '=') - s.begin();
- else {correct = false;}
- if (op == find(all(s), '-') - s.begin() and m[0] == 0) {op = m[1];}
- bool negf=false, negs=false, negt=false;
- // cout << op << "\n" << eq << "\n";;
- if (op == 0 or op > eq or op + 1 == eq or eq == n - 1 or op == -1 or eq == -1) {correct = false;
- // cout << "false\n";
- }
- int first = 0, second = 0, third = 0;
- for (int i = 0; i < op; i++) {
- if (s[i] == '-' and i == 0) {negf = true; continue;
- // cout << "first\n";
- }
- if (s[i] >= '0' and s[i] <= '9') first = first * 10 + (s[i] - '0');
- else {correct = false;
- // cout << "false first\n" << s[i] << "\n";
- }
- }
- for (int i = op + 1; i < eq; i++) {
- if (s[i] == '-' and i == op + 1) {negs = true; continue;
- // cout << "second\n";
- }
- if (s[i] >= '0' and s[i] <= '9') second = second * 10 + (s[i] - '0');
- else {correct = false;
- // cout << "false second\n";
- }
- }
- for (int i = eq + 1; i < n; i++) {
- if (s[i] == '-' and i == eq + 1) {negt = true; continue;
- // cout << "third" << "\n";
- }
- if (s[i] >= '0' and s[i] <= '9') third = third * 10 + (s[i] - '0');
- else {correct = false;
- // cout << "false third\n";
- }
- }
- if (negf) first = -first;
- if (negs) second = -second;
- if (negt) third = -third;
- if (correct) {
- if (s[op] == '+') {
- if (first + second == third) cout << "YES";
- else cout << "NO";
- } else if (s[op] == '-') {
- if (first - second == third) cout << "YES";
- else cout << "NO";
- } else if (s[op] == '*') {
- if (first * second == third) cout << "YES";
- else cout << "NO";
- } else if (s[op] == '/') {
- if ((double)first / second == (double)third) cout << "YES";
- else cout << "NO";
- } else cout << "ERROR";
- } else cout << "ERROR";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement