f | import itertools | f | import itertools |
| import sys | | import sys |
| ALPHABET = '!"(),:;%АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЫЬЭЮЯ'.encode('koi8-r') | | ALPHABET = '!"(),:;%АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЫЬЭЮЯ'.encode('koi8-r') |
n | cd = ['cp037', 'cp1006', 'cp1250', 'cp1251', 'cp1253', 'cp1254', 'cp1255', 'cp1256', 'cp1257', 'cp1258', 'cp437', 'cp720', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp864', 'cp866', 'cp869', 'cp874', 'cp875', 'hp_roman8', 'iso8859_10', 'iso8859_16', 'iso8859_4', 'iso8859_5', 'koi8_r', 'latin_1', 'mac_croatian', 'mac_greek', 'mac_iceland', 'mac_latin2'] | n | cods = ['cp037', 'cp1006', 'cp1250', 'cp1251', 'cp1253', 'cp1254', 'cp1255', 'cp1256', 'cp1257', 'cp1258', 'cp437', 'cp720', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp864', 'cp866', 'cp869', 'cp874', 'cp875', 'hp_roman8', 'iso8859_10', 'iso8859_16', 'iso8859_4', 'iso8859_5', 'koi8_r', 'latin_1', 'mac_croatian', 'mac_greek', 'mac_iceland', 'mac_latin2'] |
| b = sys.stdin.read().rstrip() | | strr = sys.stdin.read().rstrip() |
| headtail = b[:4] + b[-4:] | | startEnd = strr[0:4] + strr[-4:] |
| if 'KM' in headtail or '×{´F' in headtail: | | if 'KM' in startEnd or '×{´F' in startEnd: |
| b = b.split('%') | | strr = strr.split('%') |
| else: | | else: |
n | b = b.split('\n') | n | strr = strr.split('\n') |
| if headtail == 'ПРОЦКНЦ;': | | if startEnd == 'ПРОЦКНЦ;': |
| print('\n'.join(b)) | | print('\n'.join(strr)) |
| sys.exit() | | sys.exit() |
| codes_len1 = {} | | codes_len1 = {} |
n | for (i, j) in itertools.permutations(cd, 2): | n | for (i, j) in itertools.permutations(cods, 2): |
| try: | | try: |
| codes_len1[(j, i),] = ALPHABET.decode(i).encode(j) | | codes_len1[(j, i),] = ALPHABET.decode(i).encode(j) |
n | if headtail.encode(i).decode('koi8-r') == 'ПРОЦКНЦ;': | n | if startEnd.encode(i).decode('koi8-r') == 'ПРОЦКНЦ;': |
| for seq in b: | | for seq in strr: |
| print(seq.encode(i).decode('koi8-r')) | | print(seq.encode(i).decode('koi8-r')) |
| sys.exit() | | sys.exit() |
| except (UnicodeDecodeError, UnicodeEncodeError): | | except (UnicodeDecodeError, UnicodeEncodeError): |
| continue | | continue |
| codes_len2 = {} | | codes_len2 = {} |
| for (el, value) in codes_len1.items(): | | for (el, value) in codes_len1.items(): |
n | for (i, j) in itertools.permutations(cd, 2): | n | for (i, j) in itertools.permutations(cods, 2): |
| if el[0][0] == i: | | if el[0][0] == i: |
| continue | | continue |
| try: | | try: |
| codes_len2[((j, i),) + el] = value.decode(i).encode(j) | | codes_len2[((j, i),) + el] = value.decode(i).encode(j) |
n | if headtail.encode(i).decode(el[0][0]).encode(el[0][1]).decode('koi8-r') == 'ПРОЦКНЦ;': | n | if startEnd.encode(i).decode(el[0][0]).encode(el[0][1]).decode('koi8-r') == 'ПРОЦКНЦ;': |
| for seq in b: | | for seq in strr: |
| print(seq.encode(i).decode(el[0][0]).encode(el[0][1]).decode('koi8-r')) | | print(seq.encode(i).decode(el[0][0]).encode(el[0][1]).decode('koi8-r')) |
| sys.exit() | | sys.exit() |
| except (UnicodeDecodeError, UnicodeEncodeError): | | except (UnicodeDecodeError, UnicodeEncodeError): |
| continue | | continue |
| for (el, value) in codes_len2.items(): | | for (el, value) in codes_len2.items(): |
n | for (i, j) in itertools.permutations(cd, 2): | n | for (i, j) in itertools.permutations(cods, 2): |
| if el[0][0] == i: | | if el[0][0] == i: |
| continue | | continue |
| try: | | try: |
| ((v1, v2), (v3, v4)) = el | | ((v1, v2), (v3, v4)) = el |
t | if headtail.encode(i).decode(v1).encode(v2).decode(v3).encode(v4).decode('koi8-r') == 'ПРОЦКНЦ;': | t | if startEnd.encode(i).decode(v1).encode(v2).decode(v3).encode(v4).decode('koi8-r') == 'ПРОЦКНЦ;': |
| for num in range(len(b)): | | for num in range(len(strr)): |
| b[num] = b[num].encode(i).decode(v1).encode(v2).decode(v3).encode(v4).decode('koi8-r') | | strr[num] = strr[num].encode(i).decode(v1).encode(v2).decode(v3).encode(v4).decode('koi8-r') |
| print('\n'.join(b)) | | print('\n'.join(strr)) |
| sys.exit() | | sys.exit() |
| except (UnicodeDecodeError, UnicodeEncodeError): | | except (UnicodeDecodeError, UnicodeEncodeError): |
| continue | | continue |