-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path!19. Nuts and Bolts Problem - v2.py
More file actions
61 lines (46 loc) · 1.47 KB
/
!19. Nuts and Bolts Problem - v2.py
File metadata and controls
61 lines (46 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#User function Template for python3
class Solution:
def matchPairs(self, nuts, bolts, n):
#code here
order = ['!', '#', '$', '%', '&', '*', '?', '@', '^']
# Créer des dictionnaires pour enregistrer les positions des écrous et des boulons
nuts_dict = {nut: nut for nut in nuts}
bolts_dict = {bolt: bolt for bolt in bolts}
# Trier les écrous et les boulons selon l'ordre spécifié
sorted_nuts = []
sorted_bolts = []
for char in order:
if char in nuts_dict:
sorted_nuts.append(nuts_dict[char])
if char in bolts_dict:
sorted_bolts.append(bolts_dict[char])
# Remplacer les éléments dans les listes d'origine
for i in range(n):
nuts[i] = sorted_nuts[i]
bolts[i] = sorted_bolts[i]
#{
# Driver Code Starts
#Initial Template for Python 3
if __name__ == '__main__':
tc = int(input())
while tc > 0:
n = int(input())
nuts = list(map(str, input().strip().split()))
bolts = list(map(str, input().strip().split()))
ob = Solution()
ob.matchPairs(nuts, bolts, n)
for x in nuts:
print(x, end=" ")
print()
for x in bolts:
print(x, end=" ")
print()
tc -= 1
# } Driver Code Ends
# Tested inputs :
'''
1
5
@ % $ # ^
% @ # $ ^
'''