Created
June 1, 2018 12:17
-
-
Save hanjae-jea/9d98a4aa15c4f4342cc97cd23edb4f5a to your computer and use it in GitHub Desktop.
제한재 선생님 답변
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* // 1번 | |
#include <stdio.h> | |
int arr[105][105] = {0,}; // 배열 크기는 넉넉하게 0으로 초기화 | |
int main(void) | |
{ | |
int n, m; | |
scanf("%d %d", &n, &m); // 입력 | |
int x = 0, y = 0, k = 1; | |
// k는 n*m 만큼 숫자가 늘어난다. // 벽에 마주치거나, 이미 숫자가 들어있는 경우 중단해야 함. | |
arr[x][y] = k++; | |
while( k <= n*m ){ | |
// 달팽이를 그리는 순서대로 진행 1. → y++ | |
while( y+1 < m && arr[x][y+1] == 0 ){ | |
arr[x][++y] = k++; | |
} | |
// 2. ↓ | |
while( x+1 < n && arr[x+1][y] == 0 ){ | |
arr[++x][y] = k++; | |
} | |
// 3. ← | |
while( y-1 >= 0 && arr[x][y-1] == 0 ){ | |
arr[x][--y] = k++; | |
} | |
// 4. ↑ | |
while( x-1 >= 0 && arr[x-1][y] == 0 ){ | |
arr[--x][y] = k++; | |
} | |
} | |
// 출력 | |
for( int i = 0 ; i < n ; i ++ ){ | |
for( int j = 0 ; j < m ; j ++ ){ | |
printf("%d ", arr[i][j]); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} | |
*/ | |
// 2번 | |
#include <stdio.h> | |
int arr[15][15]; // 배열은 넉넉하게 | |
int main(void) | |
{ | |
int n; | |
scanf("%d", &n); | |
// 입력 | |
for( int i = 0 ; i < n ; i ++ ){ | |
scanf("%d", &arr[i][0]); | |
} | |
for( int i = 0 ; i < n ; i ++ ){ | |
for( int j = 1 ; j <= i ; j ++ ){ | |
arr[i][j] = arr[i][j-1] - arr[i-1][j-1]; | |
} | |
} | |
// 출력 | |
for( int i = 0 ; i < n ; i ++ ){ | |
for( int j = 0 ; j <= i ; j ++ ){ | |
printf("%d ", arr[i][j]); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment