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