比赛 20121030 评测结果 AAAAAAAAAA
题目名称 外星密码 最终得分 100
用户昵称 QhelDIV 运行时间 0.005 s
代码语言 C++ 内存使用 3.51 MiB
提交时间 2012-10-30 21:03:55
显示代码纯文本
  1. #include <fstream>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <cstdlib>
  5. using namespace std;
  6. ifstream fin("passworda.in");
  7. ofstream fout("passworda.out");
  8. string S,Ans;
  9. int top=0,pos=0;
  10. class STACK
  11. {
  12. public:
  13. int V,Multiple;
  14. string R;
  15. }stack[20001];
  16. void Initialize()
  17. {
  18. fin>>S;
  19. S.insert(0,"[1");
  20. S.push_back(']');
  21. }
  22.  
  23. string DFS()
  24. {
  25. int Ti;
  26. string Q="\0";
  27. pos++;
  28. if('0'<=S[pos+1] && S[pos+1]<='9')
  29. Ti=(S[pos]-'0')*10+S[pos+1]-'0',pos+=2;
  30. else
  31. Ti=S[pos]-'0',pos++;
  32. while(S[pos]!=']')
  33. {
  34. while(S[pos]=='[')
  35. Q+=DFS();
  36. if(S[pos]==']')
  37. break;
  38. Q.push_back(S[pos]);
  39. pos++;
  40. }
  41. string P=Q;
  42. for(int i=2;i<=Ti;i++)
  43. Q+=P;
  44. pos++;
  45. return Q;
  46. }
  47.  
  48. int main()
  49. {
  50. Initialize();
  51. fout<<DFS()<<endl;
  52. fin.close();
  53. fout.close();
  54. return 0;
  55. }