比赛 |
20121030 |
评测结果 |
AAAAAAAAAA |
题目名称 |
外星密码 |
最终得分 |
100 |
用户昵称 |
王者自由 |
运行时间 |
0.005 s |
代码语言 |
C++ |
内存使用 |
3.29 MiB |
提交时间 |
2012-10-30 20:12:11 |
显示代码纯文本
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <stack>
- #include <algorithm>
- using namespace std;
- const int N = 20000 + 10;
- struct fu {
- int p;
- string c;
- } e;
- stack<fu> s;
- char c[N];
- string t;
- inline bool num(char x) {
- return x >= '0' && x <= '9';
- }
- int main() {
- freopen("passworda.in", "r", stdin);
- freopen("passworda.out", "w", stdout);
- gets(c);
- for(int i=0; c[i]; i++) {
- if(c[i] == '[') {
- e.p = 0, e.c = "";
- for(i++; num(c[i]); i++)
- e.p = e.p * 10 + (c[i] - '0');
- while(c[i] != '[' && c[i] != ']')
- e.c += c[i++];
- //fprintf(stderr, "(%d %s)\n", e.p, e.c.c_str());
- s.push(e); i--;
- } else if(c[i] == ']') {
- e = s.top();
- //fprintf(stderr, "{%d %s}\n", e.p, e.c.c_str());
- for(int j=1; j<e.p; j++)
- s.top().c += e.c;
- e = s.top(); s.pop();
- //fprintf(stderr, "[%d %s]\n", e.p, e.c.c_str());
- if(s.empty()) t += e.c;
- else s.top().c += e.c;
- } else if(s.empty()) {
- t += c[i];
- } else {
- s.top().c += c[i];
- }
- } printf("%s\n", t.c_str());
- return 0;
- }