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));
- }
- int fibonacci(int q) {
- if (q == 0) return 0;
- if (q < 3) return 1;
- return fibonacci(q - 1) + fibonacci(q - 2);
- }
- 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;
- 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;
- int n = s.size();
- if (op == 0 or op > eq or op + 1 == eq or eq == n - 1 or op == -1 or eq == -1) correct = false;
- int first = 0, second = 0, third = 0;
- for (int i = 0; i < op; i++) {
- if (s[i] >= '0' and s[i] <= '9') first = first * 10 + (s[i] - '0');
- else correct = false;
- }
- for (int i = op + 1; i < eq; i++) {
- if (s[i] >= '0' and s[i] <= '9') second = second * 10 + (s[i] - '0');
- else correct = false;
- }
- for (int i = eq + 1; i < n; i++) {
- if (s[i] >= '0' and s[i] <= '9') third = third * 10 + (s[i] - '0');
- else correct = false;
- }
- 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