fork download
  1. #include <iostream>
  2. #include <stack>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9. stack <int> stack1;
  10. int n;
  11. int arr[10];
  12. int j=0;
  13. string comd;
  14.  
  15. cin>>n;
  16.  
  17. for(int i=0; i<n; i++)
  18. {
  19. do
  20. {
  21. cin>>comd;
  22.  
  23. if(comd=="+")
  24. {
  25. if(j<9)
  26. {
  27. cin>>arr[j];
  28. stack1.push(arr[j]);
  29. cout<<":)"<<endl;
  30. j++;
  31. }
  32. else cout<<":("<<endl;
  33.  
  34. }
  35.  
  36. else if(comd=="-")
  37. {
  38. if(stack1.size()==0) cout<<":("<<endl;
  39.  
  40. else
  41. {
  42. j--;
  43. cout<<arr[j]<<endl;
  44. stack1.pop();
  45. }
  46.  
  47. }
  48.  
  49. }while(true);
  50.  
  51.  
  52. }
  53.  
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Standard output is empty