解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class A1096 { public static void main(String args[]) { int n1 = 1; Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); int m = sc.nextInt(); if (n == 0 && m == 0) break; String a[] = new String[n]; char b[][] = new char[n][m]; int c[][] = new int[n][m]; for (int j = 0; j < a.length; j++) { a[j] = sc.next(); for (int k = 0; k < a[j].length(); k++) { b[j][k] = a[j].charAt(k); if (b[j][k] == '*'&&n!=1) { if (j == 0 && k == 0) { c[j + 1][k]++; c[j][k + 1]++; c[j+1][k + 1]++; } else if (j == 0 && k != 0 && k != c[0].length-1) { c[j][k + 1]++; c[j][k - 1]++; c[j + 1][k]++; c[j+1][k + 1]++; c[j+1][k - 1]++; } else if (j == 0 && k == c[0].length-1) { c[j + 1][k]++; c[j][k - 1]++; c[j+1][k - 1]++; } else if (j != 0 && j != c.length-1 && k == 0) { c[j + 1][k]++; c[j - 1][k]++; c[j][k + 1]++; c[j-1][k + 1]++; c[j+1][k + 1]++; } else if (j != 0 && j != c.length-1 && k == c[j].length-1) { c[j + 1][k]++; c[j - 1][k]++; c[j][k - 1]++; c[j+1][k - 1]++; c[j-1][k - 1]++; } else if (j == c.length-1 && k == 0) { c[j - 1][k]++; c[j][k + 1]++; c[j-1][k + 1]++; } else if (j == c.length-1 && k != 0 && k != c[j].length-1) { c[j - 1][k]++; c[j][k - 1]++; c[j][k + 1]++; c[j-1][k + 1]++; c[j-1][k - 1]++; } else if (j == c.length-1 && k == c[j].length-1) { c[j - 1][k]++; c[j][k - 1]++; c[j-1][k - 1]++; } else { c[j - 1][k]++; c[j - 1][k+1]++; c[j + 1][k]++; c[j - 1][k-1]++; c[j + 1][k+1]++; c[j + 1][k-1]++; c[j][k - 1]++; c[j][k + 1]++; } } if (b[j][k] == '*'&&n==1) { if (j == 0 && k == 0) { c[j][k + 1]++; } else if (j == 0 && k != 0 && k != c[0].length-1) { c[j][k + 1]++; c[j][k - 1]++; } else if (j == 0 && k == c[0].length-1) { c[j][k - 1]++; } } } } System.out.println("Field #" + n1 + ":"); n1++; for (int j = 0; j < c.length; j++) { for (int k = 0; k < c[j].length; k++) { if (b[j][k] == '*') { System.out.print(b[j][k]); continue; } else System.out.print(c[j][k]); } System.out.println(); } System.out.println(); } } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题12.1 (C语言代码)浏览:1026 |
字符串输入输出函数 (Java代码)浏览:1498 |
C语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:689 |
回文数字 (C语言代码)浏览:2539 |
1012题解浏览:938 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:627 |
C语言训练-排序问题<1> (C语言代码)浏览:369 |
C语言训练-百钱百鸡问题 (C语言代码)浏览:541 |
ACM俱乐部密码浏览:948 |
金额的中文大写浏览:3751 |