请教一下codeforces上236A_Boy or Girl

19 views
Skip to first unread message

张正林-1700018419

unread,
Oct 9, 2018, 10:48:32 AM10/9/18
to cs101pku
Pycharm中可以运行,但是提交到codeforces后显示
Can't compile file:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Programs\Python-3\lib\encodings\cp1251.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 52: character maps to <undefined>
Test.py

文亦质

unread,
Oct 9, 2018, 11:17:34 AM10/9/18
to cs101pku
你需要把其中的中文注释删掉。
其中的”明“字会导致codefources编码错误无法编译

在 2018年10月9日星期二 UTC+9下午11:48:32,张正林-1700018419写道:

文亦质

unread,
Oct 9, 2018, 11:58:20 AM10/9/18
to cs101pku
我们上传的文件是以二进制数据进入cf服务器的,而服务器必须以某种形式将其编码。
在通常情况下计算机是使用的ANSI编码,所以出现乱码是很正常的。

但这里不只是乱码的问题,而是出现了无法编码的问题。
通过错误提示,可以找到并打开cp1251.py,发现这是一种常见的文字编码cp1251(Windows Cyrillic)的解码表。(一种英文和西里尔字母的编码)
注意到”明“的UTF-8编码是0x e6 98 8e(0x代表之后的数是16进制)
而这种编码中0x 98是没有定义的。

    '\u2014'   #  0x97 -> EM DASH
   '\ufffe'   #  0x98 -> UNDEFINED(***)
   '\u2122'   #  0x99 -> TRADE MARK SIGN

所以所有utf-8编码中出现了0x 98的在cf上都会编译出错



在 2018年10月9日星期二 UTC+9下午11:48:32,张正林-1700018419写道:
Pycharm中可以运行,但是提交到codeforces后显示

petite lapine

unread,
Oct 9, 2018, 12:05:41 PM10/9/18
to cs10...@googlegroups.com
感谢详细解答,明白了。

Sent by iOS mail
--
您收到此邮件是因为您订阅了Google网上论坛上“cs101pku”群组中的主题。
要退订此主题,请访问https://groups.google.com/d/topic/cs101pku/cOhKgPCGCLQ/unsubscribe
要退订此群组及其所有主题,请发送电子邮件到cs101pku+u...@googlegroups.com
要发帖到此群组,请发送电子邮件至cs10...@googlegroups.com
访问此群组:https://groups.google.com/group/cs101pku
要查看更多选项,请访问https://groups.google.com/d/optout
Reply all
Reply to author
Forward
0 new messages