f | import sys | f | import sys |
n | data = sys.stdin.buffer.read() | n | input_data = sys.stdin.buffer.read() |
| encodings = ['koi8-r', 'cp1251', 'mac-cyrillic', 'cp866', 'iso8859_5', ' | | codecs = ['koi8-r', 'cp1251', 'mac-cyrillic', 'cp866', 'iso8859_5', 'cp8 |
| cp855'] | | 55'] |
| found = False | | is_text_found = False |
| for orig_enc in encodings: | | for original_encoding in codecs: |
| for trans_src_enc in encodings: | | for intermediate_encoding in codecs: |
| for trans_tgt_enc in encodings: | | for target_encoding in codecs: |
| try: | | try: |
n | unicode_str = data.decode(trans_tgt_enc) | n | intermediate_str = input_data.decode(target_encoding) |
| data_in_trans_src_enc = unicode_str.encode(trans_src_enc | | reencoded_data = intermediate_str.encode(intermediate_en |
| ) | | coding) |
| decoded_text = data_in_trans_src_enc.decode(orig_enc) | | final_text = reencoded_data.decode(original_encoding) |
| if 'Зимбабве' in decoded_text: | | if 'Зимбабве' in final_text: |
| print(decoded_text) | | print(final_text) |
| found = True | | is_text_found = True |
| break | | break |
| except (UnicodeDecodeError, UnicodeEncodeError): | | except (UnicodeDecodeError, UnicodeEncodeError): |
| continue | | continue |
n | if found: | n | if is_text_found: |
| break | | break |
n | if found: | n | if is_text_found: |
| break | | break |
t | if not found: | t | if not is_text_found: |
| print('Could not recover the original text.') | | print('Failed to recover the original text.') |