最后,输出矩阵。
模拟方法第一次写的时候写废了,因为自己模拟的方法是在太龌龊。之所以采用这种龌龊的方法是因为曾经这样AC过一个题,下面给出这次的AC代码,以后也要继续优化自己的代码风格。
len
=
r
*
c
/
5
;
int rr,cc,bot,top,ls,rs; // bot,top,ls,rs表示上下左右的边界值
bot = r - 1 ;
top = 0 ;
ls = 0 ;
rs = c - 1 ;
rr = 0 ;
cc = 0 ;
memset(num, 0 , sizeof (num));
for (t = 0 ;t < len;t ++ )
{
for (tt = 0 ;tt < 5 ;tt ++ )
{
num[t] += ((op[rr][cc] - ' 0 ' ) << ( 5 - tt - 1 ));
if (rr == top && cc != rs)
cc ++ ;
else if (cc == rs && rr != bot)
rr ++ ;
else if (rr == bot && cc != ls)
cc -- ;
else if (cc == ls && rr != top + 1 )
rr -- ;
else if (cc == ls && rr == top + 1 )
{
top ++ ;
bot -- ;
rs -- ;
ls ++ ;
cc ++ ;
}
}
}
int rr,cc,bot,top,ls,rs; // bot,top,ls,rs表示上下左右的边界值
bot = r - 1 ;
top = 0 ;
ls = 0 ;
rs = c - 1 ;
rr = 0 ;
cc = 0 ;
memset(num, 0 , sizeof (num));
for (t = 0 ;t < len;t ++ )
{
for (tt = 0 ;tt < 5 ;tt ++ )
{
num[t] += ((op[rr][cc] - ' 0 ' ) << ( 5 - tt - 1 ));
if (rr == top && cc != rs)
cc ++ ;
else if (cc == rs && rr != bot)
rr ++ ;
else if (rr == bot && cc != ls)
cc -- ;
else if (cc == ls && rr != top + 1 )
rr -- ;
else if (cc == ls && rr == top + 1 )
{
top ++ ;
bot -- ;
rs -- ;
ls ++ ;
cc ++ ;
}
}
}