fork(1) download
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<queue>
  5. #include<algorithm>
  6. #include<string>
  7. #include<map>
  8. #include<set>
  9. #include<fstream>
  10. #include<math.h>
  11. #include<iomanip>
  12. #include<time.h>
  13. #include<assert.h>
  14. #include<stack>
  15. using namespace std;
  16. #define ll long long
  17. #define ull unsigned long long
  18. #define db double
  19. #define inf 1000000007
  20. #define mod 1000000007
  21. #define pii pair<int,int>
  22. #define vi vector<int>
  23. #define VS vector<string>
  24. #define all(x) x.begin(),x.end()
  25. #define mp make_pair
  26. #define pb push_back
  27. #define x first
  28. #define y second
  29. #define N 100005
  30. #define pi 3.14159265358979323846
  31. #define DBG(vari) cerr<<#vari<<"="<<(vari)<<endl;
  32. #define FOREACH(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();i++)
  33.  
  34. char s[1005][1005];
  35. stack<int>q;
  36. void cal(int u)
  37. {
  38. if(u==1)printf("</ol>\n");
  39. else if(u==2)printf("</ul>\n");
  40. else printf("</li>\n");
  41. }
  42. void parse(int l,int r,int i)
  43. {
  44. if(l>r)
  45. {
  46. int u;
  47. while(!q.empty())u=q.top(),cal(u),q.pop();
  48. return;
  49. }
  50. if(s[l][i]!='#'&&s[l][i]!='*')
  51. {
  52. if(!q.empty())printf("<li>\n%s\n</li>\n",s[l]+i);
  53. else printf("%s\n",s[l]);
  54. parse(l+1,r,i);return;
  55. }
  56. int m=l;
  57. while(m<=r&&s[m][i]==s[l][i])m++;
  58. if(m-l==1)
  59. {
  60. if(!q.empty())printf("<li>\n%s\n</li>\n",s[l]+i);
  61. else printf("%s\n",s[l]);
  62. parse(l+1,r,i);return;
  63. }
  64. if(!q.empty())q.push(3),printf("<li>\n");
  65. if(s[l][i]=='#')q.push(1),printf("<ol>\n");
  66. else q.push(2),printf("<ul>\n");
  67. parse(l,m-1,i+1);
  68. parse(m,r,i);
  69. }
  70. int main()
  71. {
  72. //freopen("input.txt","r",stdin);
  73. //freopen("output.txt","w",stdout);
  74. int T,i,j,ca=0,m,k,n=0;
  75. while(~scanf("%s",s[n]))n++;
  76. parse(0,n-1,0);
  77. return 0;
  78. }
Success #stdin #stdout 0s 4416KB
stdin
Standard input is empty
stdout
Standard output is empty