hdu 火车入队 stack

  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <stack>
  4. #include <string>
  5. #include <string.h>
  6. using namespace std;
  7. int main()
  8. {
  9. int n;
  10. //string in,out;
  11. char in[1000],out[1000];
  12. while(cin>>n>>in>>out)
  13. {
  14. //stack<char> s;
  15. char s[1000];
  16. memset(s,'',sizeof(s) );
  17. int mark[20];
  18. int i=0,j=0;
  19. int count=0;
  20. while(i<n)
  21. {
  22. //if(s.empty() )
  23. if(strlen(s)==0)
  24. {
  25. //s.push(in[i]);
  26. s[count++]=in[i];
  27. mark[i+j]=0;
  28. i++;
  29. }
  30. //if(!s.empty() && s.top()!=out[j] )
  31. if(strlen(s)!=0 && s[strlen(s)]!=out[j] )
  32. {
  33. //s.push(in[i]);
  34. s[count++]=in[i];
  35. mark[i+j]=0;
  36. i++;
  37. }
  38. //while(!s.empty() &&s.top() ==out[j] )
  39. while(strlen(s)!=0 && s[strlen(s)-1]==out[j] )
  40. {
  41. //s.pop();
  42. s[strlen(s)-1]='';
  43. mark[i+j]=1;
  44. j++;
  45. }
  46. }
  47. //if( s.empty() )
  48. if(strlen(s)==0 )
  49. {
  50. cout<<"Yes."<<endl;
  51. for(int i=0;i<2*n;i++)
  52. {
  53. if(mark[i]==0)
  54. cout<<"in"<<endl;
  55. else
  56. cout<<"out"<<endl;
  57. }
  58. cout<<"FINISH"<<endl;
  59. }
  60. else
  61. cout<<"No."<<endl<<"FINISH"<<endl;
  62. }
  63. return 0;
  64. }





附件列表

    原文地址:https://www.cnblogs.com/sober-reflection/p/8bba4e1739996814cb08c2053d283f2e.html