使用BufferedWriter.write() 代替 System.out.print() 就可以AC
API中对于BufferedWriter的write(int c)解释为“Writes a single character”,所以其实写入的数据类型为char,内存长度只有2个字节,而且是以Unicode编码,所以会出现乱码。故需要wirte(c + “”),将输入类型装换为String类型即可。
import java.util.Scanner;
import java.io.*;
class Main{
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
BufferedWriter buf = new BufferedWriter(new OutputStreamWriter(System.out));
int n = sc.nextInt();
int m = sc.nextInt();
int q = sc.nextInt();
int[][] b = new int[n+2][m+2];
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
insert(b, i, j, i, j, sc.nextInt());
}
}
while(q-- > 0){
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
int c = sc.nextInt();
insert(b, x1, y1, x2, y2, c);
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <=m; j++){
b[i][j] = b[i-1][j] + b[i][j-1] - b[i-1][j-1] + b[i][j];
buf.write(b[i][j] + " ");
}
buf.write("\n");
}
buf.flush();
}
private static void insert(int[][] b, int x1, int y1, int x2, int y2, int c){
b[x1][y1] += c;
b[x2+1][y1] -= c;
b[x1][y2+1] -= c;
b[x2+1][y2+1] += c;
}
}