File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+ from collections import defaultdict
3+
4+ input = sys .stdin .readline
5+
6+ def bt (word , length ):
7+ if length == len (word ):
8+ print ('' .join (word ))
9+ return
10+ for a in alpha :
11+ # 해당 알파벳을 사용할 수 있다면
12+ if alpha [a ]:
13+ alpha [a ] -= 1
14+ bt (word + a , length )
15+ alpha [a ] += 1
16+
17+ n = int (input ())
18+ for _ in range (n ):
19+ word = sorted (list (map (str , input ().rstrip ())))
20+ alpha = defaultdict (int )
21+ for w in word :
22+ alpha [w ] += 1
23+
24+ bt ('' , len (word ))
Original file line number Diff line number Diff line change 1+ import sys
2+
3+ input = sys .stdin .readline
4+
5+ result = 0
6+ def bt (word , length ):
7+ global result
8+ if len (word ) == length :
9+ if word == s :
10+ result = 1
11+ return
12+ return
13+ if word [- 1 ] == 'A' :
14+ bt (word [:- 1 ], length )
15+ if word [0 ] == 'B' :
16+ bt (word [1 :][::- 1 ], length )
17+
18+ s = input ().rstrip ()
19+ t = input ().rstrip ()
20+ bt (t , len (s ))
21+
22+ print (result )
23+ """
24+ A
25+ BABA
26+
27+ A
28+ ABBA
29+ """
You can’t perform that action at this time.
0 commit comments