아래는 제가 짠 소스인데요.
입력된 코드를 2차원으로, 암호를 풀기위한 규칙에 따라
코드를 재배열 한 후에 재배열된 코드를 5개씩 끊어서 암호를 풀었는데요.
WA가뜨네요.
뭐가 문제일까요?
혹시 이 문제 AC받으신분 코드좀 공유해 주시면 안될까요?
#include
int main()
{
int N;
int r;
int c;
int d;
int left, top, bottom, right;
int x, y;
int i;
char code[400];
char sorted_code[400];
int code_length;
int base;
int decode;
int str_idx;
char msg[100];
scanf("%d", &N);
for(i=0; i
{
scanf("%d", &r);
scanf("%d", &c);
scanf("%s", code);
left=0;
right=c;
top=0;
bottom=r;
code_length=0;
while(top
{
for(d=0; d<4; d++)<br />
{
if(d==0)
{
for(x=left; x
sorted_code[code_length++]=code[top*c+x];
top++;
}
else if(d==1)
{
for(y=top; y
sorted_code[code_length++]=code[y*c+(right-1)];
right--;
}
else if(d==2)
{
for(x=right-1; x>=left; x--)
sorted_code[code_length++]=code[(bottom-1)*c+x];
bottom--;
}
else{
for(y=bottom-1; y>=top; y--)
sorted_code[code_length++]=code[y*c+left];
left++;
}
}//end for loop
}//end while loop
base=16;
decode=0;
str_idx=0;
for(x=0; x<=code_length; x++)<br />
{
if(base==0)
{
if(decode==0) msg[str_idx++]=' ';
else msg[str_idx++]=decode+'A'-1;
base=16;
decode=0;
}
decode=decode+(sorted_code[x]-'0')*base;
base=base/2;
}
msg[str_idx]='\0';
printf("%d %s\n",i+1, msg);
}
return 0;
}//end of main
It looks like you're new here. If you want to get involved, click one of these buttons!