Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CheckSymbolBalance
#include<bits/stdc++.h> using namespace std; bool isSymbolsBalanced(string input) { stack<char> stk; char x ; for(auto i: input) { if(i == '{' || i == '[' || i == '(') { cout<<"push : "<<i<<"\n"; stk.push(i); continue; } if(stk.empty()) { return false; } switch(i) { case '}': { x = stk.top(); stk.pop(); if(x != '{') { cout<<" pop :: "<<x<<"\n"; return false; } break; } case ']': { x = stk.top(); stk.pop(); if(x != '[') { cout<<" pop :: "<<x<<"\n"; return false; } break; } case ')': { x = stk.top(); stk.pop(); if(x != '(') { cout<<" pop :: "<<x<<"\n"; return false; } break; } } } return stk.empty(); } int main() { string sym = "{[()[]]}}"; cout<<isSymbolsBalanced(sym); return 0; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Dar
C++ Array printing
frequsency
Ploshtina na pravoagolnik
Classes Pt 2 c++
Identifying polimorphic types without using RTTI or type mappings
Przesylka
Dar
Palindromy
11 და 16 აპრილს დამუსავებული
Please log in to post a comment.