http://acm.pku.edu.cn/JudgeOnline/problem?id=3290用STL水过了~
1 #include <cstdio>
2 #include <vector>
3 #include <deque>
4
5 using namespace std;
6
7 const int MAX_N = 110;
8
9 char st[MAX_N];
10 int n;
11 vector<char> num, op;
12 deque<char> ret;
13
14 int main() {
15 while (scanf("%s", st), st[0] != '0') {
16 num.clear(); op.clear(); n = 0;
17 for (int i = 0; st[i]; ++i) {
18 if (st[i] >= 'a') num.push_back(st[i]);
19 else if (st[i] == 'N') ++n;
20 else op.push_back(st[i]);
21 }
22 if (num.empty()) {
23 puts("no WFF possible");
24 continue;
25 }
26 ret.clear();
27 ret.push_front(num[0]);
28 while (n--) ret.push_front('N');
29 for (int i = 1, j = 0; i < num.size() && j < op.size(); ) {
30 ret.push_front(num[i++]);
31 ret.push_front(op[j++]);
32 }
33 for (int i = 0; i < ret.size(); ++i) putchar(ret[i]);
34 puts("");
35 }
36 return 0;
37 }
38