UTF-8 Bytes Info
Python
Medium
2 views
Problem Description
A line string s is provided (can contain spaces). Convert it to UTF-8 bytes. Output two integers: byteLength and checksum (sum of bytes modulo 256).
Input Format
One line string s.
Output Format
One line: length checksum.
Official Solution
import sys
s=sys.stdin.read()
if s is None: sys.exit(0)
if s.endswith('\
'):
s=s[:-1]
b=s.encode('utf-8')
chk=0
for x in b:
chk=(chk+x)%256
sys.stdout.write(f'{len(b)} {chk}')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!