forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhan.py
More file actions
executable file
Β·68 lines (55 loc) Β· 1.95 KB
/
han.py
File metadata and controls
executable file
Β·68 lines (55 loc) Β· 1.95 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
62
63
64
65
66
67
68
#!/usr/bin/env python3
class Solution:
"""
@param: strs: a list of strings
@return: encodes a list of strings to a single string.
"""
def encode(self, strs):
return '-'.join([
'.'.join([
str(ord(c))
for c in s
])
for s in strs
])
"""
@param: str: A string
@return: decodes a single string to a list of strings
"""
def decode(self, str):
return [
''.join([
chr(int(c))
for c in s.split('.')
])
for s in str.split('-')
]
# μλλ κ°λ¨ν ν
μ€νΈ μ½λ
import random
def generate_random_string(min_length=5, max_length=20):
# Choose a random string length between min_length and max_length
string_length = random.randint(min_length, max_length)
# Define the character categories
alphabets = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
numbers = '0123456789'
hanguls = 'κ°λλ€λΌλ§λ°μ¬μμμ°¨μΉ΄ννν'
emojis = ['π', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π’', 'π±']
# Probability of selecting from each category
weights = [0.25, 0.25, 0.25, 0.25]
# Combine all categories into a single list
all_chars = list(alphabets + numbers + hanguls) + emojis
# Select characters based on the weights and create the final string
random_chars = random.choices(all_chars, k=string_length)
random_string = ''.join(random_chars)
return random_string
def generate_multiple_random_strings():
strings_list = []
# Generate a random number of strings, between 1 and 10
number_of_strings = random.randint(1, 10)
for _ in range(number_of_strings):
random_string = generate_random_string()
strings_list.append(random_string)
return strings_list
strs = generate_multiple_random_strings()
print(strs)
print(strs==Solution().decode(Solution().encode(strs)))