Run Code
|
API
|
Code Wall
|
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
Microsoft - MaxEmployeeAttendence (R repititions - Semi Optimised DP)
LIS
Expected GCD
CodeChef P2 - FIZZA
HeapSort
compile-time check of existness of method of a class
decode
Click 5
PreDir2
Metodos