f | import itertools | f | import itertools |
| import sys | | import sys |
| ALPHABET = '!"(),:;%АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЫЬЭЮЯ'.encode('koi8-r') | | ALPHABET = '!"(),:;%АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЫЬЭЮЯ'.encode('koi8-r') |
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'] | 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'] |
| strr = sys.stdin.read().rstrip() | | b = sys.stdin.read().rstrip() |
| startEnd = strr[0:4] + strr[-4:] | | headtail = b[:4] + b[-4:] |
| if 'KM' in startEnd or '×{´F' in startEnd: | | if 'KM' in headtail or '×{´F' in headtail: |
| strr = strr.split('%') | | b = b.split('%') |
| else: | | else: |
n | strr = strr.split('\n') | n | b = b.split('\n') |
| if startEnd == 'ПРОЦКНЦ;': | | if headtail == 'ПРОЦКНЦ;': |
| print('\n'.join(strr)) | | print('\n'.join(b)) |
| sys.exit() | | sys.exit() |
| codes_len1 = {} | | codes_len1 = {} |
n | for (i, j) in itertools.permutations(cods, 2): | n | for (i, j) in itertools.permutations(cd, 2): |
| try: | | try: |
| codes_len1[(j, i),] = ALPHABET.decode(i).encode(j) | | codes_len1[(j, i),] = ALPHABET.decode(i).encode(j) |
n | if startEnd.encode(i).decode('koi8-r') == 'ПРОЦКНЦ;': | n | if headtail.encode(i).decode('koi8-r') == 'ПРОЦКНЦ;': |
| for seq in strr: | | for seq in b: |
| 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(cods, 2): | n | for (i, j) in itertools.permutations(cd, 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 startEnd.encode(i).decode(el[0][0]).encode(el[0][1]).decode('koi8-r') == 'ПРОЦКНЦ;': | n | if headtail.encode(i).decode(el[0][0]).encode(el[0][1]).decode('koi8-r') == 'ПРОЦКНЦ;': |
| for seq in strr: | | for seq in b: |
| 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(cods, 2): | n | for (i, j) in itertools.permutations(cd, 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 startEnd.encode(i).decode(v1).encode(v2).decode(v3).encode(v4).decode('koi8-r') == 'ПРОЦКНЦ;': | t | if headtail.encode(i).decode(v1).encode(v2).decode(v3).encode(v4).decode('koi8-r') == 'ПРОЦКНЦ;': |
| for num in range(len(strr)): | | for num in range(len(b)): |
| strr[num] = strr[num].encode(i).decode(v1).encode(v2).decode(v3).encode(v4).decode('koi8-r') | | b[num] = b[num].encode(i).decode(v1).encode(v2).decode(v3).encode(v4).decode('koi8-r') |
| print('\n'.join(strr)) | | print('\n'.join(b)) |
| sys.exit() | | sys.exit() |
| except (UnicodeDecodeError, UnicodeEncodeError): | | except (UnicodeDecodeError, UnicodeEncodeError): |
| continue | | continue |