http://acm.pku.edu.cn/JudgeOnline/problem?id=2612
输入布局,和操作,
如果点位空白要输出该点周围的雷数(0~8)
但没有点到雷这输出操作往后的布局。如果点到了雷,还要输出所有的雷,
package com.woxiaoe.acm.pku.P2612;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
static char[][] table,touchTable,showTable;
static int[][] counts;
static int[] X = {0,-1,-1,-1,0,1,1,1};
static int[] Y = {-1,-1,0,1,1,1,0,-1};
public static void main(String[] args) {
//Scanner scn = new Scanner(System.in);
Scanner scn = new Scanner(Main.class.getResourceAsStream("in.dat"));
PrintWriter out = new PrintWriter(System.out);
int n;
n = scn.nextInt();
table = new char[n][n];
touchTable = new char[n][n];
showTable = new char[n][n];
counts = new int[n][n];
boolean touched = false;
for(int i = 0; i < n; i++){
table[i] = scn.next().toCharArray();
}
for(int i = 0; i < n; i++){
touchTable[i] = scn.next().toCharArray();
}
int xi = 0 ,yj = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(table[i][j] == '*'){
for(int k = 0; k < 8; k ++){
xi = i + X[k];
yj = j + Y[k];
if((xi < n && xi >= 0) && (yj < n && yj >= 0) && table[xi][yj] != 'x'){
counts[xi][yj]++;
}
}
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0 ; j < n; j++){
showTable[i][j] = '.';
if(touchTable[i][j] == 'x' && table[i][j] == '.'){//没有猜到雷的情况
showTable[i][j] = (char)(counts[i][j] + 48);
}else if(touchTable[i][j] == 'x' && table[i][j] == '*'){
touched = true;
}
}
}
if(touched){
for(int i = 0 ; i < n; i++){
for(int j = 0; j < n; j++){
if(table[i][j] == '*'){
showTable[i][j] = '*';
}
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j ++){
out.print(showTable[i][j]);
}
out.println();
}
out.flush();
}
}
分享到:
相关推荐
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
北大POJ1159-Palindrome 解题报告+AC代码
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj分类poj分类poj分类poj分类
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
北大POJ2002-Squares 解题报告+AC代码
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
POJ1048,加强版的约瑟夫问题 难度中等
POJ1083的代码,POJ1083的代码,POJ1083的代码
poj 百练 题目分类 poj 百练 题目分类
POJ上的一道题目,自己写的代码,因为想下载别人的, 所以就放上了。
poj 1001答案
POJ2968代码有用,欢迎下载,POJ代码
Poj中一些题目的源代码,里面共有二十多道题目,OI
北大POJ3253-POJ3253-Fence Repair【STL优先队列】 解题报告+AC代码