1954. 달팽이 숫자

SW 업무 관련/SW Expert Academy

1954. 달팽이 숫자

WillBe_ 2018. 7. 1. 20:21


열혈c에 이 문제가 있었던 것으로 기억한다.


모든 문제를 풀었지만...이 문제는 못 풀고 넘어간 기억이 난다.


지금은 풀 수 있겠지!!!했지만.......다른 사람의 풀이를 보고 말았다ㅜ,ㅠ


설명은 코드를 보면...굳이 필요가 없을 것이다!



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <string.h>
int map[11][11];
 
int main()
{
    int x, y, Test, num, Direction, len, Length;
 
    scanf("%d"&Test);
 
    for (int i = 1; i <= Test; i++)
    {
        x = 0;
        Direction = 1; num = 1; y = 1;
        memset(map, 0sizeof(map));
        scanf("%d",&len);
        Length = len;
        while (len >= 0)
        {
            for (int a = 1; a <= len; a++)
            {
                x += Direction;
                map[y][x] = num++;
            }
 
            if (--len < 0)
                break;
 
            for (int a = 1; a <= len; a++)
            {
                y += Direction;
                map[y][x] = num++;
            }
            Direction *= -1;
 
        }
        printf("#%d\n",i);
        for (int a = 1; a <= Length; a++)
        {
            for (int b = 1; b <= Length; b++)
            {
                printf("%d ", map[a][b]);
            }
            printf("\n");
        }
    }
    return 0;
}
cs