简单记录下解题过程
# include <stdio.h>
void main(){
int data[8][8] =
{{6,8,7,8,4,9,4,3}
,{6,5,7,6,1,9,3,3}
,{9,3,5,1,7,6,3,8}
,{2,5,2,6,7,2,4,9}
,{6,7,1,6,4,7,1,3}
,{4,8,8,2,3,3,7,8}
,{5,2,4,5,9,4,9,2}
,{6,2,3,1,2,1,3,4}};
int lineFirst = 0 , lineLast = 7 ,rowFirst = 0 , rowLast = 7 ;
int sign = 0 ;
while(1){
if( sign == 0 ){
printf( "\n" );
for ( int num = rowFirst ; num <= rowLast ; num ++ ){
printf( "%d" , data[lineFirst][num] );
}
lineFirst ++ ;
sign = 1 ;
if ( lineFirst == lineLast ){
return ;
}
}
if ( sign == 1 ){
printf( "\n" );
for ( int num = lineFirst ; num <= lineLast ; num ++ ){
printf("%d" , data[num][rowLast] );
}
rowLast -- ;
sign = 2 ;
if ( rowLast == rowFirst ){
return ;
}
}
if ( sign == 2 ){
printf( "\n" );
for ( int num = rowLast ; num >= rowFirst ; num -- ){
printf("%d",data[lineLast][num]);
}
lineLast -- ;
sign = 3 ;
if ( lineFirst == lineLast ){
return ;
}
}
if ( sign == 3 ){
printf( "\n" );
for ( int num = lineLast ; num >= lineFirst ; num -- ){
printf( "%d" , data[num][rowFirst] );
}
rowFirst ++ ;
sign = 0 ;
if ( rowLast == rowFirst ){
return ;
}
}
}
}
|