#네이버 문제
# include <stdio.h>
# include <stdlib.h>
# include <stdbool.h>
# define S 5
typedef struct _Spin
{
char Mat[5][5];
char** ptrMat;
}Spin, *ptrSpin;
ptrSpin _createNode_();
void _init_(Spin** param);
void _before_(Spin** param);
void _mov_(Spin** param);
int main(void)
{
ptrSpin my_pnode = NULL;
my_pnode = _createNode_();
_init_(&my_pnode);
_before_(&my_pnode);
_mov_(&my_pnode);
//_before_(&my_pnode);
free(my_pnode);
return 0;
} // end of main function
ptrSpin _createNode_()
{
ptrSpin pNode = (ptrSpin)malloc(sizeof(Spin));
return pNode;
} // end of _createNode_ function
void _init_(Spin** param)
{
char letter = 'a';
if ((*param) == NULL)
{
fprintf(stderr, "malloc error ... !!! \n");
exit(1);
}
else
{
// [1]
(** param).ptrMat = NULL;
// [2]
for (int i = 0; i < S; i++)
{
for (int j = 0; j < S; j++)
{
(** param).Mat[i][j] = letter;
letter = (char)((int)letter + 1);
}
}
}
} // end of _init_ function
void _before_(Spin** param)
{
printf("************* 변형 전 *************** \n");
for (int i = 0; i < S; i++)
{
for (int j = 0; j < S; j++)
{
printf("%c ", (** param).Mat[i][j]);
}
printf("\n");
}
printf("************* 변형 후 *************** \n");
}
void _mov_(Spin** param)
{
char tmpMat[S][S] = { '\0', };
int tmp = 0;
int t_i, t_j;
int i, j;
// TEMP STEP
for (i = 0; i < S; i++)
{
for (j = 0; j < S; j++)
{
t_i = i;
t_j = j;
switch (i)
{
case 0:
// y = x 축 대칭
tmp = t_i;
t_i = t_j;
t_j = tmp;
// y => +4 이동
t_j = (t_j + 4) % S;
tmpMat[t_i][t_j] = (** param).Mat[i][j];
break;
case 1:
// y = x 축 대칭
tmp = t_i;
t_i = t_j;
t_j = tmp;
// y => +2 이동
t_j = (t_j + 2) % S;
tmpMat[t_i][t_j] = (** param).Mat[i][j];
break;
case 2:
// y = x 축 대칭
tmp = t_i;
t_i = t_j;
t_j = tmp;
tmpMat[t_i][t_j] = (** param).Mat[i][j];
break;
case 3:
// y = x 축 대칭
tmp = t_i;
t_i = t_j;
t_j = tmp;
// y => -2 이동
t_j = (t_j - 2) % S;
tmpMat[t_i][t_j] = (** param).Mat[i][j];
break;
case 4:
// y = x 축 대칭
tmp = t_i;
t_i = t_j;
t_j = tmp;
// y => -2 이동
t_j = (t_j - 4) % S;
tmpMat[t_i][t_j] = (** param).Mat[i][j];
break;
} // end of switch
} // end of for inner
} // end of for out
for (int i = 0; i < S; i++)
{
for (int j = 0; j < S; j++)
{
printf("%c ", tmpMat[i][j]);
}
printf("\n");
}
} // end of _mov_ function