日期:2014-05-18  浏览次数:20665 次

算法,有兴趣的高手进来试试
写一个算法实现:将其按“从左到右、从上到下”的顺序,后退一位,第一位(rows(0),columns(0))由被移出的最后一位(rows(x-1),columns(x-1))填上。

例如(当x=3):
1   2   3         step   1             9   1   2         step   2                 8   9   1
4   5   6   ------------->   3   4   5   -------------->     2   3   4     ......
7   8   9                                 6   7   8                                     5   6   7

算法想了很久,没有想出来..希望高手写出来.用冒牌法好象不行.

------解决方案--------------------
class Program
{
static void Main()
{
const int GO = 3;
int[] myArray = new int[GO * GO];
for (int i = 0; i < GO * GO; i++)
{
myArray[i] = i+1;
}
for (int v = 0; v < GO * GO; v++)
{
for (int a = 0; a < GO * GO; a++)
{
int[] newArray = new int[GO * GO];
int s = a - v;
if (s <0)
s = s + GO * GO;
newArray[a] = myArray[s];
Console.Write( "{0} ", newArray[a]);
if((a+1)%GO==0)
Console.WriteLine();
}
Console.WriteLine();
}
Console.ReadLine();
}

}