Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define maxn 1000000
- #include <string>
- using namespace std;
- char a[maxn+10];
- int length;
- int head;
- int stack_init() {
- length = 0;
- }
- bool stack_is_empty() {
- if (length == 0)
- return true;
- else return false;
- }
- bool add_element (char c) {
- if (head == maxn)
- return false;
- a[head] = c;
- head++;
- length++;
- return true;
- }
- bool take_element (char c) {
- if (stack_is_empty())
- return false;
- c = a[--head];
- length--;
- return true;
- }
- char top_element() {
- if (!stack_is_empty())
- return a[length - 1];
- }
- int main() {
- bool answer = true;
- char s[256];
- cin>>s;
- for (int i = 0; i< sizeof(s); i++) {
- if ((int)(s[i]) == 40 || (int)(s[i]) == 91 || (int)(s[i]) == 123) {
- add_element(s[i]);
- }
- else {
- if (stack_is_empty()) {
- answer = false;
- break;
- }
- else {
- char last = top_element();
- if (((int)(s[i]) == 91 && (int)(last) == 93)||((int)(s[i]) == 40 && (int)(last) == 41)||((int)(s[i]) == 123 && (int)(last) == 125))
- take_element(s[i]);
- else {
- answer = false;
- break;
- }
- }
- }
- }
- if (answer)
- cout<<"YES";
- else cout<<"NO";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement