Advertisement
J00ker

Untitled

Mar 11th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. struct Stiva
  7. {
  8. int a[1001], top;
  9.  
  10. void Init()
  11. {top = -1;}
  12.  
  13. int Empty()
  14. {
  15. if(top == -1) return 1;
  16. return 0;
  17. }
  18.  
  19. void Push(int x)
  20. {a[++top] = x;}
  21.  
  22. void Pop()
  23. {if(!Empty()) top--;}
  24.  
  25. int Top()
  26. {return a[top];}
  27.  
  28. };
  29.  
  30. int main()
  31. {
  32. char s[1001], i;
  33. Stiva st;
  34.  
  35. ifstream fin("paranteze.in");
  36. fin >> s;
  37. fin.close();
  38.  
  39. for(i = 0; s[i] != 0; i++)
  40. {
  41. if(s[i] == '(')
  42. st.Push(i);
  43. else
  44. {
  45. cout << st.Top() << "\n";
  46. st.Pop();
  47. }
  48. }
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement