1 #define _for(i,a,b) for(int i = (a);i < b;i ++)
2 class Solution
3 {
4 public:
5 vector<string> rnt;
6 vector<string> LIST;
7 int n;
8 void dfs(int cur,string s)
9 {
10 if(cur==n)
11 {
12 rnt.push_back(s);
13 return ;
14 }
15 _for(i,0,LIST[cur].size())
16 {
17 dfs(cur+1,s+LIST[cur][i]);
18 }
19 }
20 vector<string> permute(string S)
21 {
22 vector<string> li(100);
23 n = 0;
24 int in = 0;
25 int st = 0;
26 _for(i,0,S.size())
27 {
28 if(S[i]==',')
29 continue;
30 if(S[i]=='{')
31 {
32 st = 1;
33 }
34 else if(S[i]=='}')
35 {
36 st = 0;
37 in ++;
38 n ++;
39 }
40
41 else if(st==1)
42 li[in].push_back(S[i]);
43 else if(st==0)
44 {
45 li[in++].push_back(S[i]);
46 n ++;
47 }
48 }
49 LIST = li;
50 string ss;
51 dfs(0,ss);
52 sort(rnt.begin(),rnt.end());
53 return rnt;
54 }
55 };