Skip to content

Instantly share code, notes, and snippets.

Created October 14, 2014 13:00
Show Gist options
  • Save anonymous/3627407d7f97cd37d0e9 to your computer and use it in GitHub Desktop.
Save anonymous/3627407d7f97cd37d0e9 to your computer and use it in GitHub Desktop.
package sunwooks;
//1)차이가뭔지 파일,IOException
import java.io.File;
import java.util.Scanner;
import java.io.IOException;
public class Fire {
public static void main(String[] args)throws IOException{
//read
Scanner inFile =new Scanner(new File("input4.txt"));
int m=inFile.nextInt();
int n=inFile.nextInt();
int d=inFile.nextInt();
if(m<3 || m>10) {
System.out.println("잘못된 입력입니다");
return;
}
if(n<3 || n>10) {
System.out.println("잘못된 입력입니다");
return;
}
if(d<3 || d>10) {
System.out.println("잘못된 입력입니다");
return;
}
char[][] field = new char[m][n];
for(int i=0; i<m; i++){
String line =inFile.next();
if(line.length() !=n){
System.out.println("잘못된 입력입니다");
return;
}
field[i]=line.toCharArray();
}
//2)infile.close의 위치
inFile.close();
for(int i=0; i<m; i++){
for(int j=0;j<n; j++){
System.out.print(field[i][j]);
}
System.out.println();
}
System.out.println();
for(int day=0;day<d;day++) {
for(int i=0;i<m;i++) {
for(int j=0;j<n;j++) {
/* 불이 번지는 것을 *로 표현하면 배열 검사하면서 불이 계속 번져나가기 때문에
* 임시로 #으로 한 뒤 한번에 #을 *로 바꿔줌
*/
if(field[i][j]=='*') {
//상
if(i > 0) {
if(field[i-1][j]=='0') {
field[i-1][j] = '#';
}
}
//하
if(i < m-1) {
if(field[i+1][j] == '0') {
field[i+1][j] = '#';
}
}
//좌
if(j > 0) {
if(field[i][j-1] == '0') {
field[i][j-1] = '#';
}
}
//우
if(j < n-1) {
if(field[i][j+1] == '0') {
field[i][j+1] = '#';
}
}
field[i][j] = '+';
}
}
}
//#을 *로 바꿔줌
for(int i=0;i<m;i++) {
for(int j=0;j<n;j++) {
if(field[i][j]=='#') {
field[i][j] = '*';
}
}
}
System.out.println("Day "+(day+1) );
for(int i=0;i<m;i++) {
for(int j=0;j<n;j++) {
System.out.print(field[i][j]);
}
System.out.println();
}
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment