We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8e9335d commit 7b173eeCopy full SHA for 7b173ee
1 file changed
live11/test112/문제1/백한결.py
@@ -0,0 +1,36 @@
1
+import sys
2
+
3
+def main():
4
+ input = sys.stdin.readline
5
+ N = int(input())
6
7
+ for i in range(N):
8
+ word = str(input().strip())
9
10
+ word = sorted(list(word))
11
12
+ result = []
13
+ backtracking(word, [], [False] * len(word), result)
14
15
+ for r in result:
16
+ print(r)
17
18
+def backtracking(word, path, visited, result):
19
+ if len(path) == len(word):
20
+ result.append("".join(path))
21
+ return
22
23
+ for i in range(len(word)):
24
+ if visited[i]:
25
+ continue
26
+ if i > 0 and word[i] == word[i-1] and not visited[i-1]:
27
28
29
+ visited[i] = True
30
+ path.append(word[i])
31
+ backtracking(word, path, visited, result)
32
+ path.pop()
33
+ visited[i] = False
34
35
+if __name__ == '__main__':
36
+ main()
0 commit comments