Text Files · 16 / 17 Exercise Medium

Characters and bytes

Objective

A character and a byte are not the same: in UTF-8 letters such as é take 2 bytes and other symbols up to 4. In Latin-1 each character takes 1 byte, but there are only 256 of them.

Instructions

  • The first line has the number n of lines; each one is a text.
  • Show N characters, B bytes in UTF-8, L in Latin-1. If the text cannot be encoded in Latin-1, show not representable instead of the number.
Input
3
hello
café
日本
Output
5 characters, 5 bytes in UTF-8, 5 in Latin-1
4 characters, 5 bytes in UTF-8, 4 in Latin-1
2 characters, 6 bytes in UTF-8, not representable in Latin-1

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise