|
http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=3045 [복사]
드디어 다 끝냈습니다.
지금까지 노래들으면서 하니깐 집중도 안되고 이랬는데
아이유노래는 집중이 잘되네요 ㅋㅋㅋㅋ
일단 "prosthetics" 님 정말 감사해요
관계성 찾기에서 관계성의 뜻도 모르고 (한쿸어 노무 햑해효) 어떻게 해야될지 몰랐었는데 정말 좋은 글써주셔서 잘 할수있었습니다^^
그리고
"endosymbiosis" 이분 코드 써주셨는데 반대긴 했지만 첨에 딱 실행해보고 이분 뭐지!!하고 영감을 받았습니다
어쨋든 제 코드와 endosymbiosis님의 코드 둘다 써볼께요^^
::
제꺼::
#include <stdio.h>
int main(void)
{
int n; //sides
int a,b;
int count=1;
int arr[16][16]; //16 is the most optimazation
int i,j;
printf("숫자를 입력하시오(1 - 16): ");
scanf("%d", &n);
printf("\n");
if(n%2==0)
{
for(b=1;count!=n*n+1;b++)
{
for(a=b-1;a<=n-b;a++)
arr[b-1][a]=count++;
for(a=b;a<=n-b;a++)
arr[a][n-b]=count++;
for(a=n-b-1;a>=b-1;a--)
arr[n-b][a]=count++;
for(a=n-b-1;a>=b;a--)
arr[a][b-1]=count++;
}
}
else
{
for(b=1;count!=n*n+1;b++)
{
for(a=b-1;a<=n-b;a++)
arr[b-1][a]=count++;
for(a=b;a<=n-b;a++)
arr[a][n-b]=count++;
for(a=n-b-1;a>=b-1;a--)
arr[n-b][a]=count++;
for(a=n-b-1;a>=b;a--)
arr[a][b-1]=count++;
}
}
for(i=0;i<=n-1;i++)
{
for(j=0;j<=n-1;j++)
printf("%4d ", arr[i][j]);
printf("\n");
}
return 0;
}
endosymbiosis님의 코드::
#include<stdio.h>
int main(void)
{
int input, array[15][15]={0}, i=0, j=0, top=0, bottom=0, count=1, direct=1;
printf("Input your number (1-15):");
scanf("%d", &input);
bottom=input;
while(array[i][j]==0)
{
if(direct)
{
if(i<bottom-1)
array[i++][j]=count++;
else if(j<bottom)
array[i][j++]=count++;
if(j==bottom)
{
i--;
j--;
bottom--;
direct=0;
}
}
else
{
if(i>top)
array[i--][j]=count++;
else if(j>top)
array[i][j--]=count++;
if(j==top)
{
j++;
i++;
top++;
direct=1;
}
}
};
for(i=0;i<input;i++)
{
for(j=0;j<input;j++)
{
printf("%4d", array[i][j]);
}
printf("\n");
}
printf("\n");
return 0;
}
제꺼는 16이 maximum이고 endodjsfklfjsdkf님은 15가 max인데요
15나 16이 제 cmd창을 꽉채울수있는거고
더 위로 17이상으로 가면 더럽게 나가요
그러니깐 15나 16이 딱 적당해요 ㅎㅎ
어쨋든 도와주신분 감사합니다^^ |
Hit : 5792 Date : 2011/06/09 02:39
|