Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- #include <stack>
- using namespace std;
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- string s;
- cin >> s;
- stack<char> c;
- for (int i = 0; i < s.size(); i++) {
- if (s[i] == ')') {
- if (c.size() == 0) {
- printf("at position %d : expected ( or END, found )", i + 1);
- return 0;
- }
- if (c.top() == '|') {
- c.pop();
- c.pop();
- }
- else {
- printf("at position %d : expected ( or |, found (", i + 1);
- return 0;
- }
- }
- if (s[i] == '|') {
- if (c.size() == 0) {
- printf("at position %d : expected (, found |", i + 1);
- return 0;
- }
- if (c.top() == '|') {
- printf("at position %d : expected ( or ), found |", i + 1);
- return 0;
- }
- c.push('|');
- }
- if (s[i] == '(') {
- c.push('(');
- }
- }
- if (c.size() == 0) {
- cout << "correct, length = " << s.size();
- return 0;
- }
- if (c.size() != 0) {
- if (c.top() == '(') {
- printf("at position %d: expected ( or |, found END", s.size() + 1);
- return 0;
- }
- else {
- printf("at position %d: expected ( or ), found END", s.size() + 1);
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement