import java.io.PrintStream; import java.io.UnsupportedEncodingException; /** * 这是一套专门解决在线OJ平台提交代码有中文时UTF-8和GBK字符集的问题的模版 */ public class Main { public static void main(String[] args) throws UnsupportedEncodingException { //后续在OJ平台中,如果有中文的输入和输出,记得在main方法中加: //为什么会报错,测试用例不通过,原因是 我们写的代码是UTF-8字符集,但是在线OJ平台使用的是GBK字符集。 // 使用的是UTF-8 编码,使用GBK解码 // 我增加了额外的一个代码设置,设置所有的系统输出语句都要遵循UTF-8字符集编码和解码 System.setOut(new PrintStream(System.out,true,"UTF-8")); //后面写代码 } //后面写代码.... }