If we cannot kill the snake, it is clear that village is damaged by snake.
Many people are under investigation to kill the snake.
We also receive the mission that we write sequence number on it's body.
The number is written as sequence from 1.
Let's solve the problem hurry and save the our village
-Input is txt file.
The name is "input.txt"
Input file consist of like below.
.size of width, size of height
.map information
-output
You should save as "output.txt".
The file include sequence number about snake.
--------------------------------------------------------
μ΄λ€ λ§μμ κ±°λν λ±μ΄ λνλ¬λ€.
빨리 λ±μ μ£½μ΄μ§ μμΌλ©΄ λ§μμ ν° νΌν΄κ° μ¨λ€.
μ¬λλ€μ μ΄ λ±μ μ‘κΈ° μν μ¬λ¬κ°μ§ λ°©λ²μ μ‘°μ¬ μ€μ΄λ€.
μ°λ¦¬λ λ§μλ‘ λΆν° λ± λͺΈμ λ§λλ§λ€ μ«μλ₯Ό μ°λΌλ μ무λ₯Ό λ°μλ€.
μ«μλ 1μ μμμΌλ‘ μμ°¨μ μΌλ‘ κΈ°λ‘ν΄μΌ νλ€.
μ~ 빨리 λ±μ λ§λμ μ«μλ₯Ό μ°κ³ λ§μμ ꡬνμ~!
μ λ ₯
λ§μ κ°λ‘ν¬κΈ°, λ§μ μΈλ‘ν¬κΈ°
λ§μκ³Ό λ±μ λνλ΄λ 격μ
μΆλ ₯
λ±μ λ§λμ μμ°¨μ μ μ«μλ‘ λ체
ex1)
- input.txt -
5 5
0 0 0 0 0
0 1 1 1 0
0 0 0 1 0
0 1 1 1 0
0 0 0 0 0
-output.txt-
0 0 0 0 0
0 1 2 3 0
0 0 0 4 0
0 7 6 5 0
0 0 0 0 0
ex2)
-input.txt-
10 10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0
-output.txt-
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 2 0 0 0 0 0 0 0
0 0 3 4 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0 0
0 0 0 6 7 0 0 0 0 0
0 0 0 0 8 9 10 11 0 0
0 0 0 0 0 0 0 0 12 0
0 0 0 0 0 0 0 0 13 0
0 0 0 0 0 0 0 0 0 0
%λ±μ 머리λ νμ 꼬리λ λͺΈμ μμΉλ³΄λ€ μΌμͺ½ κ·Έλ¦¬κ³ μμͺ½μ μ‘΄μ¬νλ€.
%input.txt νμΌμ μ½μ΄μ output.txt νμΌλ‘ μΆλ ₯νλ κ²μ λͺ©νλ‘ νλ€.
%λ±μ νμ 90λλ‘ κΊ½μ¬μλ€. μ¦, λκ°μ μΌλ‘ μ°κ²°λμ΄ μμ§ μλ€!
*Sample code for read file and Dynamic allocation.
FILE * fp; fp = fopen("input.txt","r"); //Read Width, Height int w,h; fscanf(fp,"%d",&w); fscanf(fp,"%d",&h); //Dynamic allocation about w,h sizes int **map; map = new int*[h]; for(int i=0; i<h; ++i) map[i] = new int[w]; //Read map information for(int i=0; i<h; ++i) for(int j=0; j<w; ++j) fscanf(fp,"%d",&(map[i][j]) ); //Confirmation for(int i=0; i<h; ++i) { for(int j=0; j<w; ++j) printf("%d ", map[i][j] ); printf("\n"); } //memory release for(int i=0; i<h; ++i) delete map[i]; delete[] map; //File close fclose(fp); ///