Advertisement
J00ker

Untitled

Mar 11th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int n;
  7.  
  8. struct Stiva
  9. {
  10. int a[1001], top;
  11.  
  12. void Init()
  13. {
  14. top = -1;
  15. }
  16.  
  17. int Empty()
  18. {
  19. if(top == -1) return 1;
  20. return 0;
  21. }
  22.  
  23. int Full()
  24. {
  25. if(top == n-1) return 1;
  26. return 0;
  27. }
  28.  
  29. void Push(int x)
  30. {
  31. a[++top] = x;
  32. }
  33.  
  34. void Pop()
  35. {
  36. if(!Empty()) top--;
  37. }
  38.  
  39. int Top()
  40. {
  41. if(Empty()) return 0;
  42. return a[top];
  43. }
  44.  
  45. };
  46.  
  47. int main()
  48. {
  49. Stiva s, s1, s2;
  50. s.Init();
  51. s1.Init();
  52. s2.Init();
  53. int i, x, f = 0;
  54.  
  55. ifstream fin("s1.in");
  56. fin >> n;
  57. for(i = 0; i < n; i++)
  58. {
  59. fin >> x;
  60. s1.Push(x);
  61. }
  62. fin.close();
  63.  
  64. while(!s2.Full() && f == 0)
  65. {
  66. x = s1.Top();
  67. s1.Pop();
  68.  
  69. if(x == s2.Top() + 1)
  70. {
  71. s2.Push(x); cout << 1 << "\n";
  72. }
  73.  
  74. else if(x > s.Top())
  75. {
  76. s.Push(x); cout << 2 << "\n";
  77. }
  78.  
  79. if(s.Top() == s2.Top() + 1)
  80. {
  81. s2.Push(s.Top()); cout << 3 << "\n";
  82. s.Pop();
  83. }
  84. if((s1.Top() != s2.Top()+1) && (s.Top() > s2.Top()))
  85. f++;
  86. }
  87.  
  88. if(s2.Full()) cout << "da";
  89. else cout << "nu";
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement