比赛 20121030 评测结果 AAAAAAAAAA
题目名称 外星密码 最终得分 100
用户昵称 王者自由 运行时间 0.005 s
代码语言 C++ 内存使用 3.29 MiB
提交时间 2012-10-30 20:12:11
显示代码纯文本
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <string>
  4. #include <stack>
  5. #include <algorithm>
  6. using namespace std;
  7. const int N = 20000 + 10;
  8. struct fu {
  9. int p;
  10. string c;
  11. } e;
  12. stack<fu> s;
  13. char c[N];
  14. string t;
  15. inline bool num(char x) {
  16. return x >= '0' && x <= '9';
  17. }
  18. int main() {
  19. freopen("passworda.in", "r", stdin);
  20. freopen("passworda.out", "w", stdout);
  21. gets(c);
  22. for(int i=0; c[i]; i++) {
  23. if(c[i] == '[') {
  24. e.p = 0, e.c = "";
  25. for(i++; num(c[i]); i++)
  26. e.p = e.p * 10 + (c[i] - '0');
  27. while(c[i] != '[' && c[i] != ']')
  28. e.c += c[i++];
  29. //fprintf(stderr, "(%d %s)\n", e.p, e.c.c_str());
  30. s.push(e); i--;
  31. } else if(c[i] == ']') {
  32. e = s.top();
  33. //fprintf(stderr, "{%d %s}\n", e.p, e.c.c_str());
  34. for(int j=1; j<e.p; j++)
  35. s.top().c += e.c;
  36. e = s.top(); s.pop();
  37. //fprintf(stderr, "[%d %s]\n", e.p, e.c.c_str());
  38. if(s.empty()) t += e.c;
  39. else s.top().c += e.c;
  40. } else if(s.empty()) {
  41. t += c[i];
  42. } else {
  43. s.top().c += c[i];
  44. }
  45. } printf("%s\n", t.c_str());
  46. return 0;
  47. }