Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- int main()
- {
- string s;
- ll f = 0, c = 0;
- stack<int>last;
- while (getline(cin, s))
- {
- for (int i = 0; i < s.size(); i++)
- {
- if (s[i] == '(')
- {
- if (!last.empty())
- {
- if (s[i + 1] == '*'&&last.top() != 1)
- {
- c++;
- i++;
- last.push(1);
- }
- else
- if (!last.empty())
- {
- if (last.top() != 1)
- {
- last.push(0);
- f++;
- }
- }
- else
- {
- last.push(0);
- f++;
- }
- }
- else
- if (last.empty())
- {
- if (s[i + 1] == '*')
- {
- c++;
- i++;
- last.push(1);
- }
- else
- {
- last.push(0);
- f++;
- }
- }
- }
- else
- {
- if (s[i] == '*')
- {
- if (!last.empty())
- if (last.top() == 1)
- if (s[i + 1] == ')')
- {
- c--;
- last.pop();
- i++;
- }
- }
- else
- if (s[i] == ')')
- {
- if (f == 0 && c == 0)
- {
- cout << "NO";
- return 0;
- }
- else
- if (last.top() == 0)
- {
- f--;
- last.pop();
- }
- }
- else
- {
- if (!last.empty())
- {
- if (last.top() == 0)
- {
- if ((s[i] < '0' || s[i] > '9') && s[i] != '*' && s[i] != '-' && s[i] != '+' && s[i] != '/'&&s[i] != '=')
- {
- cout << "NO";
- return 0;
- }
- }
- }
- }
- }
- }
- }
- if (c == 0 && f == 0)
- {
- cout << "YES";
- }
- else
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment