Instantly share code, notes, and snippets.

# jwon0615/1469.cpp Created Mar 26, 2018

4_codeup_연습문제_배열
 #include int main(void){ int n, arr[100][100]; scanf("%d",&n); for(int i=0;i
 #include int arr[102][102]; int main(){ int cnt,n,m; scanf("%d %d",&n, &m); cnt=n*m; int x=n,y=1; while(cnt>=1){ while(arr[x][y]==0&&x>0){ arr[x--][y]=cnt--; } x++,y++; while(arr[x][y]==0&&y<=m){ arr[x][y++]=cnt--; } y--,x++; while(arr[x][y]==0&&x<=n){ arr[x++][y]=cnt--; } x--, y--; while(arr[x][y]==0&&y>0){ arr[x][y--]=cnt--; } y++,x--; } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) printf("%d ",arr[i][j]); printf("\n"); } }
 #include int arr[51][51]; int main(){ int i, j, n, diff, cnt=1; int s=0, e=-1; scanf("%d", &n); diff=n; while(cnt<=n*n){ for(i=1;i<=diff;i++) arr[s][++e]=cnt++; diff--; for(i=1;i<=diff;i++) arr[++s][e]=cnt++; for(i=1;i<=diff;i++) arr[s][--e]=cnt++; diff--; for(i=1;i<=diff;i++) arr[--s][e]=cnt++; } for(i=0;i
 #include int arr[16][16]; int main(){ int i, j, n, diff, cnt=1; int s=-1, e=0; scanf("%d", &n); diff=n; while(cnt<=n*n){ for(i=1;i<=diff;i++) arr[++s][e]=cnt++; diff--; for(i=1;i<=diff;i++) arr[s][++e]=cnt++; for(i=1;i<=diff;i++) arr[--s][e]=cnt++; diff--; for(i=1;i<=diff;i++) arr[s][--e]=cnt++; } for(i=0;i
 #include int main(){ int a[21][21],i,j,n; scanf("%d",&n); for(i=0;i
 #include int main(){ int n,num=0,arr[50][50]; scanf("%d",&n); int row=0,col=n/2; while(num<=n*n){ arr[row][col]=++num; if(num%n==0) row++; else { col++; row--; if(col==n)col=0; if(row==-1)row=n-1; } } for(int i=0;i