fork(5) download
  1. #include<iostream>
  2. #include<stdio.h>
  3. #define lim 1000005
  4. using namespace std;
  5. int main()
  6. {
  7. int t,min=lim,c=1,i,j,k,n[lim],top=0;
  8. string s;
  9. string a[lim];
  10. scanf("%d",&t);
  11. for(i=1;i<=t;i++)
  12. {
  13. scanf("%d",&k);
  14. if(k==-1)
  15. {
  16. printf("%d ",top-c);
  17. top=c;
  18. cout<<a[top]<<"\n";
  19. top--;
  20. if(top>0)
  21. {
  22. min=n[top];
  23. c=top;
  24. for(j=1;j<top;j++)
  25. {
  26. if(n[j]<min)
  27. {
  28. min=n[j];
  29. c=j;
  30. }
  31. }
  32. }
  33. continue;
  34. }
  35. else if(k==0)
  36. {
  37. cin>>s;
  38. continue;
  39. }
  40. cin>>s;
  41. n[++top]=k;
  42. a[top]=s;
  43. if(n[top]<=min)
  44. {
  45. min=n[top];
  46. c=top;
  47. }
  48. }
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.03s 10552KB
stdin
6
9 english
6 mathematics
8 geography
-1
3 graphics
-1
stdout
1 mathematics
0 graphics