반응형
    
    
    
  
                              Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 
                            Tags
                            
                        
                          
                          - BOJ
- compose
- 매개변수탐색
- @P0
- 오퍼레터
- msSQL
- incr
- 기술면접
- boj #19237 #어른 상어
- 성적평가
- Docker
- 파라메트릭
- 처우협의
- OFFSET
- BFS
- 경력
- Kafka
- 연결요소
- 백트래킹
- 퇴사통보
- 처우산정
- 13908
- 백준
- 이분탐색
- dfs
- 물채우기
- 6987
- upper_bound
- 소프티어
- softeer
                            Archives
                            
                        
                          
                          - Today
- Total
기술 블로그
달팽이 본문
728x90
    
    
  반응형
    
    
    
  문제)
하나의 자연수를 입력하여(10 이하), 예시와 같이 출력되게 하시오.(printf("%2d", ~) 사용할 것.)
예시 1)
입력 : 6
출력 : (아래 참고)
| 1 2 3 4 5 6 7 | 6  1  2  3  4  5  6 20 21 22 23 24  7 19 32 33 34 25  8 18 31 36 35 26  9 17 30 29 28 27 10 16 15 14 13 12 11 | cs | 
예시 2)
입력 : 3
출력 : (아래 참고)
| 1 2 3 4 | 3  1  2  3  8  9  4  7  6  5 | cs | 
정답 코드
| 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 49 50 51 52 53 54 55 56 57 58 | #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> using namespace std; int num = 1; int Map[1000][1000] = { 0, }; int dy[4] = { 0, 1, 0, -1 }; int dx[4] = { 1, 0, -1, 0 }; int main(void) {     int N = 0, r = 0, c = 0;     scanf("%d", &N);     for (int i = 0; i < (N + 1) / 2; i++)     {         r = i;         c = i;         for (int d = 0; d < 4; d++)         {             while (1)             {                 if(Map[r][c] == 0) Map[r][c] = num++;                     r += dy[d];                 c += dx[d];                 if (d % 2 == 0 && (c >= N - 1 - i || c <= i)) break;                 if (d % 2 == 1 && (r >= N - 1 - i || r <= i)) break;             }         }     }     for (int i = 0; i < N; i++)     {         for (int j = 0; j < N; j++)         {             printf("%2d ", Map[i][j]);         }         printf("\n");     }     return 0; } | cs | 
728x90
    
    
  반응형
    
    
    
  '알고리즘 문제 > 기타' 카테고리의 다른 글
| 백트래킹(BackTracking) 경우의 수 나열 (0) | 2019.05.19 | 
|---|---|
| 시간 날 때 마다, 계속 반복적으로 풀어볼 문제들 (0) | 2019.05.19 | 
| Zero One Algorithm Contest 2018 (0) | 2019.01.03 | 
| 막대 그래프 그리기 (0) | 2018.10.27 | 
| 길이가 N인 이진수 (0) | 2018.10.26 | 
