Using system;
Using system. Collections. Generic;
Using system. text;
Using suanfa;
Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
// Array target_list1 = new int [10] {2, 3, 5, 13, 21, 46, 89, 93,215 7, 5769 };
// Sortdome target = new sortdome (target_list1 );
// Int actual;
// Int sum = 0;
// Int Total = 0;
// Random = new random (1 );
// While (sum <10)
//{
// Int inum = 0;
// Inum = random. Next (0, 6000 );
// Actual = target. Find (inum, target. arraylist );
// If (actual> 0)
//{
// Sum ++;
//}
// Total ++;
// Console. writeline (string. format ("the {0} comparison value {1} is now found for {2} Times", inum, actual, sum, total) is generated immediately for the {3} time ));
//}
Juzhen ();
Console. Readline ();
}
Public static void test ()
{
Int A, B, C;
A = B = c = 1;
String STR = "1, 1 ";
For (INT I = 0; I <20; I ++)
{
C = A + B;
STR + = "," + C. tostring ();
Console. writeline (STR );
A = B;
B = C;
}
}
Public static void test1 ()
{
For (INT I = 1; I <10; I ++)
{
Stringbuilder sb = new stringbuilder ();
For (Int J = 1; j <= I; j ++)
{
SB. appendformat ("{0} * {1} = {2}", I, j, I * j );
}
Console. writeline (sb. tostring ());
}
}
Public static void juzhen1 ()
{
Int flag = 0;
Int nextx, nexty, num;
Int [,] arr = NULL;
Num = int. parse (system. Console. Readline ());
Arr = new int [Num, num];
Nextx = nexty = 0;
For (INT I = 1; I <= num * num; I ++)
{
Arr [nextx, nexty] = I;
Switch (FLAG)
{
Case 0: // you
If (nexty = num-1 | arr [nextx, nexty + 1]! = 0)
{
Nextx ++;
Flag = (flag + 1) % 4;
Break;
}
Else
{
Nexty ++;
Break;
}
Case 1: // Xia
If (nextx = num-1 | arr [nextx + 1, nexty]! = 0)
{
Nexty --;
Flag = (flag + 1) % 4;
Break;
}
Else
{
Nextx ++;
Break;
}
Case 2: // Zuo
If (nexty = 0 | arr [nextx, nexty-1]! = 0)
{
Nextx --;
Flag = (flag + 1) % 4;
Break;
}
Else
{
Nexty --;
Break;
}
Case 3: // Shang
If (nextx = 0 | arr [nextx-1, nexty]! = 0)
{
Nexty ++;
Flag = (flag + 1) % 4;
Break;
}
Else
{
Nextx --;
Break;
}
}
}
For (INT I = 0; I <num; I ++)
{
For (Int J = 0; j <num; j ++)
{
System. Console. Write ("{0}", arr [I, j]. tostring ("00 "));
}
System. Console. writeline ();
}
System. Console. Readline ();
}
Public static void juzhen ()
{
Int flag = 0;
Int nextx, nexty, num;
Int [,] arr = NULL;
Num = int. parse (system. Console. Readline ());
Arr = new int [Num, num];
Nextx = nexty = 0;
For (INT I = 1; I <= num * num; I ++)
{
Arr [nextx, nexty] = I;
Switch (FLAG)
{
Case 0: //
If (nexty = num-1 | arr [nextx, nexty + 1]! = 0)
{
Nextx ++;
Flag = (flag + 1) % 4;
Break;
}
Else
{
Nexty ++;
Break;
}
Case 1: // right
If (nextx = num-1 | arr [nextx + 1, nexty]! = 0)
{
Nexty --;
Flag = (flag + 1) % 4;
Break;
}
Else
{
Nextx ++;
Break;
}
Case 2: // top
If (nexty = 0 | arr [nextx, nexty-1]! = 0)
{
Nextx --;
Flag = (flag + 1) % 4;
Break;
}
Else
{
Nexty --;
Break;
}
Case 3: // left
If (nextx = 0 | arr [nextx-1, nexty]! = 0)
{
Nexty ++;
Flag = (flag + 1) % 4;
Break;
}
Else
{
Nextx --;
Break;
}
}
}
For (INT I = 0; I <num; I ++)
{
For (Int J = 0; j <num; j ++)
{
System. Console. Write ("{0}", arr [I, j]. tostring ("00 "));
}
System. Console. writeline ();
}
System. Console. Readline ();
}
}
}