今天在牛客上做到了这样一道题目:

The Orchid Pavilion(兰亭集序) is well known as the top of “行书”in history of Chinese literature. The most fascinating sentence is "Well I know it is a lie to say that life and death is the same thing, and that longevity and early death make no difference Alas!"(固知一死生为虚诞,齐彭殇为妄作).By counting the characters of the whole content (in Chinese version),the result should be 391(including punctuation). For these characters written to a text file,please select the possible file size without any data corrupt.

已知兰亭集序总长度是391个字(包括标点符号),试问他的UTF-8和UTF-16的编码长度?

一般来说,在GBK和GB2312中,汉字占2字节;TF-8中占3字节;UTF-16中占2字节

所以:

  • UTF-8: 391*3 + 3(标识)B
  • UTF-16:391*2+2(标识)B