Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int maxn = 1000;
- struct stek {
- char niza[maxn];
- int idx;
- void init() {
- idx = -1;
- }
- void push(char x) {
- if(idx + 1 >= maxn) {
- cout << "NEMA DOVOLNO KAPACITET" << endl;
- return;
- }
- idx++;
- niza[idx] = x;
- }
- char pop() {
- if(idx == -1) {
- cout << "NEMA NITU EDEN ELEMENT VO STEKOT" << endl;
- return '\0';
- }
- char result = niza[idx];
- idx--;
- return result;
- }
- char top() {
- if(idx == -1) {
- cout << "NEMA NITU EDEN ELEMENT VO STEKOT" << endl;
- return '\0';
- }
- return niza[idx];
- }
- int size() {
- return idx + 1;
- }
- int isEmpty() {
- if(idx == -1) {
- return 1;
- }
- else {
- return 0;
- }
- }
- };
- int main() {
- string s;
- cin >> s;
- stek st;
- st.init();
- for(int i = 0; i <s.size(); i++) {
- if(s[i] == '(' || s[i] == '{' || s[i] == '[') {
- st.push(s[i]);
- }
- else {
- if(s[i] == ')') {
- if(st.isEmpty() == 0 && st.top() == '(') {
- st.pop();
- }
- }
- else if(s[i] == ']') {
- if(st.isEmpty() == 0 && st.top() == '[') {
- st.pop();
- }
- }
- else if(s[i] == '}') {
- if(st.isEmpty() == 0 && st.top() == '{') {
- st.pop();
- }
- }
- }
- }
- if(st.isEmpty() == 1) {
- cout << "DA" << endl;
- }
- else {
- cout << "NE" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement