Advertisement
Adrita

task 5( ds lab 4) 3rd sem

Jan 30th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. string a;
  6. stack <char> s;
  7. cin>>a;
  8. int i,cnt=0;
  9. for(i=0; i<a.size(); i++)
  10. {
  11.  
  12. if(a[i]=='('||a[i]=='{'||a[i]=='[')
  13. {
  14. s.push(a[i]);
  15.  
  16. cnt++;
  17.  
  18. }
  19. else if(a[i]==')'||a[i]=='}'||a[i]==']')
  20. {
  21. if((a[i]==')'&&s.top()=='(')||(a[i]=='}'&&s.top()=='{')||(a[i]==']'&&s.top()=='['))
  22. {
  23.  
  24. cnt--;
  25.  
  26. s.pop();
  27.  
  28.  
  29. }
  30. }
  31. }
  32. if(cnt==0)
  33. cout<<"Yes";
  34. else
  35. cout<<"No";
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement