|
| 1 | +#!/usr/bin/env python3 |
| 2 | +class Solution: |
| 3 | + """ |
| 4 | + @param: strs: a list of strings |
| 5 | + @return: encodes a list of strings to a single string. |
| 6 | + """ |
| 7 | + def encode(self, strs): |
| 8 | + return '-'.join([ |
| 9 | + '.'.join([ |
| 10 | + str(ord(c)) |
| 11 | + for c in s |
| 12 | + ]) |
| 13 | + for s in strs |
| 14 | + ]) |
| 15 | + |
| 16 | + """ |
| 17 | + @param: str: A string |
| 18 | + @return: decodes a single string to a list of strings |
| 19 | + """ |
| 20 | + def decode(self, str): |
| 21 | + return [ |
| 22 | + ''.join([ |
| 23 | + chr(int(c)) |
| 24 | + for c in s.split('.') |
| 25 | + ]) |
| 26 | + for s in str.split('-') |
| 27 | + ] |
| 28 | + |
| 29 | + |
| 30 | +# μλλ κ°λ¨ν ν
μ€νΈ μ½λ |
| 31 | +import random |
| 32 | + |
| 33 | +def generate_random_string(min_length=5, max_length=20): |
| 34 | + # Choose a random string length between min_length and max_length |
| 35 | + string_length = random.randint(min_length, max_length) |
| 36 | + |
| 37 | + # Define the character categories |
| 38 | + alphabets = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 39 | + numbers = '0123456789' |
| 40 | + hanguls = 'κ°λλ€λΌλ§λ°μ¬μμμ°¨μΉ΄ννν' |
| 41 | + emojis = ['π', 'π', 'π', 'π', 'π', 'π', 'π', 'π', 'π’', 'π±'] |
| 42 | + |
| 43 | + # Probability of selecting from each category |
| 44 | + weights = [0.25, 0.25, 0.25, 0.25] |
| 45 | + |
| 46 | + # Combine all categories into a single list |
| 47 | + all_chars = list(alphabets + numbers + hanguls) + emojis |
| 48 | + |
| 49 | + # Select characters based on the weights and create the final string |
| 50 | + random_chars = random.choices(all_chars, k=string_length) |
| 51 | + random_string = ''.join(random_chars) |
| 52 | + |
| 53 | + return random_string |
| 54 | + |
| 55 | +def generate_multiple_random_strings(): |
| 56 | + strings_list = [] |
| 57 | + # Generate a random number of strings, between 1 and 10 |
| 58 | + number_of_strings = random.randint(1, 10) |
| 59 | + |
| 60 | + for _ in range(number_of_strings): |
| 61 | + random_string = generate_random_string() |
| 62 | + strings_list.append(random_string) |
| 63 | + |
| 64 | + return strings_list |
| 65 | + |
| 66 | +strs = generate_multiple_random_strings() |
| 67 | +print(strs) |
| 68 | +print(strs==Solution().decode(Solution().encode(strs))) |
0 commit comments