Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int arra[12], cmd;
- void push(int x) {
- cmd++;
- arra[cmd] = x;
- }
- int pop() {
- int x = arra[cmd];
- cmd--;
- return x;
- }
- bool isEmpty() {
- if (cmd == -1) {
- return true;
- }
- return false;
- }
- int top() {
- return arra[cmd];
- }
- int main() {
- int n = 10;
- char str[6] = { '(', '[', '{', ')', ']', '}' };
- const char* vars = "((([][]{}))]";
- int abstr[12];
- for (int i = 0; i < 12; i++) {
- abstr[i] = 0;
- for (int j = 0; j < 6; j++) {
- if (vars[i] == str[j]) {
- abstr[i] = j;
- break;
- }
- }
- }
- cmd = -1;
- for (int i = 0; i < 12; i++) {
- if (abstr[i] < 3) {
- push(abstr[i]);
- }
- else {
- if (abstr[i] == arra[cmd] + 3) {
- pop();
- }
- else {
- cout << "this is not correct";
- return 0;
- }
- }
- }
- if (isEmpty()) {
- cout << "this is correct";
- }
- else {
- cout << "this is not correct";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment