File size: 1,865 Bytes
f7ef4d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import random
import re

# 1. Перемешивание слов
def shuffle_words(text: str) -> str:
    words = text.split()
    random.shuffle(words)
    return ' '.join(words)

# 2. Leetspeak (русско-английский вариант)
LEET_MAP = {
    'а': '@', 'о': '0', 'е': '3', 'и': 'u', 'с': 'c', 'к': 'k', 'р': 'p',
    'т': 't', 'у': 'y', 'х': 'x', 'в': 'b', 'н': 'h', 'л': 'l', 'д': 'd',
    'ё': 'e', 'й': 'u', 'ц': 'c', 'г': 'r', 'ш': 'w', 'щ': 'w', 'з': '3',
    'ъ': 'b', 'ы': 'bI', 'ь': 'b', 'э': 'e', 'ю': 'u', 'я': 'a'
}
def to_leetspeak(text: str) -> str:
    result = []
    for ch in text.lower():
        result.append(LEET_MAP.get(ch, ch))
    return ''.join(result)


# 4. Сравнение двух текстов
def compare_texts(text1: str, text2: str) -> str:
    words1 = set(text1.split())
    words2 = set(text2.split())
    common = words1 & words2
    union = words1 | words2
    if not union:
        return "Оба текста пусты"
    similarity = len(common) / len(union) * 100
    return f"Совпадение слов: {similarity:.1f}%\nОбщих слов: {len(common)}\nВсего уникальных: {len(union)}"

# 5. Транслитерация русский→латиница (простая)
RUS_TO_LAT = {
    'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo',
    'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'y', 'к': 'k', 'л': 'l', 'м': 'm',
    'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
    'ф': 'f', 'х': 'kh', 'ц': 'ts', 'ч': 'ch', 'ш': 'sh', 'щ': 'shch',
    'ъ': '', 'ы': 'y', 'ь': '', 'э': 'e', 'ю': 'yu', 'я': 'ya'
}
def transliterate_ru_to_en(text: str) -> str:
    result = []
    for ch in text.lower():
        result.append(RUS_TO_LAT.get(ch, ch))
    return ''.join(result)