Last active
          July 11, 2022 08:46 
        
      - 
      
- 
        Save satyajeetkrjha/771a48b9557bdf9a480e337892d6084b to your computer and use it in GitHub Desktop. 
Revisions
- 
        satyajeetkrjha revised this gist Jul 11, 2022 . 1 changed file with 49 additions and 15 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,21 +2,55 @@ #include <string> #include <stack> using namespace std; int main() { string line; string res; stack<char> st ; while (getline(cin, line)) { int sz = line.size(); for(int i =0 ;i<sz;i++){ char ch = line[i]; if(ch == '(' || ch == '[' || ch == '{' || ch == ')' || ch == '}' || ch == ']'){ res+= ch; } } } int ressize = res.size(); for(int i =0 ;i<ressize;i++){ char ch = res[i]; if(ch == '(' || ch == '{' || ch == '['){ st.push(res[i]); } else{ if(st.empty()){ cout <<"invalid"<< endl; return 0; } char topchar = st.top(); st.pop(); if(topchar == '(' && ch !=')'){ cout <<"invalid"<< endl; return 0; } if(topchar == '{' && ch !='}'){ cout <<"invalid"<< endl; return 0; } if(topchar == '[' && ch !=']'){ cout <<"invalid"<<endl; return 0; } } } if(st.empty()){ cout <<"valid"<< endl; return 0; } else{ cout <<"invalid"<< endl; return 0; } } 
- 
        satyajeetkrjha created this gist Jul 11, 2022 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ #include <iostream> #include <string> #include <stack> using namespace std; int main() { string line ; string res ; while(getline(cin,line)){ for(int i =0 ; i<line.size();i++){ char ch = line[i]; if(ch == '(' || ch == '{' || ch == '[' || ch == ']' || ch == '}' || ch == ')'){ res+= ch; } } } cout << "res is " << res << endl; // moving this at line 17 prints but here it does not print anything }