Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 标程

Posted by lifuzhe0 at 2018-01-14 14:20:25 on Problem 3367
```// Author: Adrian Kuegel
// Date: 1. 6. 2007
//本题构造出表达式树后答案非常清晰，但用stl啥的会tle，标程的处理比较巧妙
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <assert.h>
#include <cctype>
using namespace std;

typedef vector<string> VS;

string code;
VS res;

void doit(int &pos, int d) {
assert(pos >= 0);
res[d] += code[pos];
--pos;
if (islower(code[pos+1]))
return;
assert(isupper(code[pos+1]));
doit(pos,d+1);
doit(pos,d+1);
}

int main() {
int tc;
//	ifstream in("expressions.in");
cin >> tc;
assert(tc >= 1 && tc <= 200);
while(tc--) {
assert(cin >> code);
assert(code.size() < 10000 && code.size() % 2 == 1);
res.assign(code.size(),"");
int pos = code.size()-1;
doit(pos, 0);
assert(pos < 0);
for (int i=0;i<code.size();i++) cout<<res[i]<<endl;
for (VS::reverse_iterator it=res.rbegin(); it!=res.rend(); ++it)
cout << *it;
cout << endl;
}
return 0;
}```

Followed by: