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