9/06/2011

Conduct an investigation about length of snake. And write sequence number on it's body.

A huge snake has appeared in our village.
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);

///