参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int [][]arr = new int[n][n]; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) arr[i][j] = scanner.nextInt(); int oddrow = 0;//记录和为奇数的行数 int row = 0;//记录和为奇数的行数的下标 for(int i = 0; i < n; i++) { int sum = 0; for(int j = 0; j < n; j++) { sum += arr[i][j]; } if(sum % 2 == 1) { oddrow++; row = i; } } int oddcolumn = 0;//记录和为奇数的列数 int column = 0;//记录和为奇数的列数的下标 for(int i = 0; i < n; i++) { int sum = 0; for(int j = 0; j < n; j++) { sum += arr[j][i]; } if(sum % 2 == 1) { oddcolumn++; column = i; } } row++;//题目答案中的下标不是从0开始,而是从1开始的 column++; if(oddcolumn == 0 && oddrow == 0) System.out.println("OK"); else if(oddcolumn == 1 && oddrow == 1) System.out.println(row + " " + column); else System.out.println("Corrupt"); } }
0.0分
5 人评分
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:517 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:552 |
ASCII帮了大忙浏览:749 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:543 |
C二级辅导-同因查找 (C语言代码)浏览:568 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:564 |
A+B for Input-Output Practice (III) (C语言代码)浏览:424 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1270 |
三角形 (C语言代码)浏览:659 |
删除数组中的0元素 (C语言代码)浏览:2041 |