Public class marquee {
Int [] [] matrix;
Int N; // Number of walk-through steps
Int time; // a parameter for controlling the end
Int rank; // level
Coordinate start; // start point
Public static void main (string [] S ){
A ma = new A (12, new coordinate (0, 0 ));
Coordinate temp = ma. Start;
While (true ){
Int oldtime = ma. Time ();
/// Here is your step
Temp = ma. rightof (temp );
Temp = ma. downof (temp );
Temp = ma. leftof (temp );
Temp = ma. upof (temp );
//
If (oldtime = ma. Time () break;
}
Ma. Print ();
}
A (INT rank, coordinate start ){
N = 1;
This. Rank = rank;
Matrix = new int [Rank] [Rank];
Time = N;
This. Start = start;
Matrix [start. x] [start. Y] = N;
}
Public int time (){
Return this. Time;
}
Public void print (){
For (INT I = 0; I <this. rank; I ++ ){
System. Out. println ();
For (Int J = 0; j <this. rank; j ++ ){
System. Out. Print (this. Matrix [I] [J] + "");
}
}
}
// Regard the matrix as the Coordinate System
// Start from the xyrightfrom coordinate to the right until the boundary is reached or the current local vertex has been written.
// Four similar methods
Private coordinate rightof (coordinate xyrightfrom) {// xyrightfrom start point to the right
Int I = xyrightfrom. X;
Int J = xyrightfrom. Y;
While (J + 1 <rank & matrix [I] [J + 1] = 0 ){
N ++;
Matrix [I] [++ J] = N;
}
If (Matrix [I] [J] = 0) matrix [I] [J] = ++ N;
Time = N;
Return new coordinate (I, j );
}
Private coordinate downof (coordinate xydownfrom ){
Int I = xydownfrom. X;
Int J = xydownfrom. Y;
While (I + 1 <rank & matrix [I + 1] [J] = 0 ){
N ++;
Matrix [++ I] [J] = N;
}
If (Matrix [I] [J] = 0) matrix [I] [J] = ++ N;
Time = N;
Return new coordinate (I, j );
}
Private coordinate leftof (coordinate xyleftfrom ){
Int I = xyleftfrom. X;
Int J = xyleftfrom. Y;
While (J-1> = 0 & matrix [I] [J-1] = 0 ){
N ++;
Matrix [I] [-- J] = N;
}
If (Matrix [I] [J] = 0) matrix [I] [J] = ++ N;
Time = N;
Return new coordinate (I, j );
}
Private coordinate upof (coordinate xyupfrom ){
Int I = xyupfrom. X;
Int J = xyupfrom. Y;
While (I-1> = 0 & matrix [I-1] [J] = 0 ){
N ++;
Matrix [-- I] [J] = N;
}
If (Matrix [I] [J] = 0) matrix [I] [J] = ++ N;
Time = N;
Return new coordinate (I, j );
}
}
Class coordinate {
Int X;
Int y;
Coordinate (int x, int y ){
This. x = X;
This. Y = y;
}
}