Все игры
Запись

Люди, помогите решить задачку, плиииииз!!!!! Очень надо!!!!!


Написать комментарий


     05-06-2008 10:59 (ссылка)
Re: Люди, помогите решить задачку, плиииииз!!!!! Очень надо!!!!!
Ну ты написал. :-))) Как математик. ;-)
Хочеш написать программу, объясняй всё терминами программирования и не забывай конкретезировать входный параметры и начальные условия.

"Квадратная матрица нечетного порядка" - это что, двумерный массив.
Если да, то какого размера? Сколко на сколько?

"последовательностью натруальных чисел"
Начиная с какого? С каким шагом? Кончая каким?

"по спирали"
По круговой или по квадратной?
     05-06-2008 21:09 (ссылка)
Re: Люди, помогите решить задачку, плиииииз!!!!! Очень надо!!!!!
public static int[,] GenerateMatrix(int size, int initValue, int step){
if (size<0) throw new System.ArgumentOutOfRangeException("Size shold be >= 0");
// Size is not the length of array.
// Size also used as max spread.
int l = size * 2 + 1; // Length is size * 2 + 1

//Initializing
int[,] ar = new int[l,l];

//Fill
int x = 0, y = 0; //Positioning performed relative to 0. Later it will be shifted to array coordinates.
int dir = 0; // Current direction 0-up , 1-right, 2-down, 3-left
int spread = 0; //Current spread, used to change direction if position is out of spread.

do{
// Offset to array cordinates
int ax = x + size;
int ay = y + size;

// Assign
ar[ax,ay] = initValue;

// Changing location and direction if needed.
switch (dir){
case 0:{ //Up
if (Math.Abs(y) < spread){
y--;
}
else{
if (spread < size){
spread ++;
y--;
dir=1;
}
else{
goto end;
}

}
} break;

case 1: //Right
if (Math.Abs(x)< spread){
x++;
}
else{
dir=2;
y++;
}
break;

case 2: //Down
if (Math.Abs(y)< spread){
y++;
}
else{
dir=3;
x--;
}
break;

case 3: //Left
if (Math.Abs(x)< spread){
x--;
}
else{
dir=0;
y--;
}
break;

}

// Changing current element
initValue += step;
} while(true);

end:
return ar;
}
     05-06-2008 21:26 (ссылка)
Re: Люди, помогите решить задачку, плиииииз!!!!! Очень надо!!!!!
Это функция Консоль апликации для тестирования

static void Main(string[] args) {
////////////////////////////////////
Console.WriteLine("---- Input ----");
Console.WriteLine("");
InputStart:
Console.Write("Enter matrix size:");
string s = Console.ReadLine();
int si = 0;
try{
si = int.Parse(s);
}
catch{
Console.WriteLine("Invalid input!");
goto InputStart;
}
//
if (si < 0){
Console.WriteLine("Invalid input!");
goto InputStart;
}
////////////////////////////////////
Console.WriteLine("");
Console.WriteLine("---- Output ----");
Console.WriteLine("");
//
int l = si * 2 + 1;
Console.WriteLine("Generating matrix: " +l.ToString() + " X " + l.ToString());
int[,] ar = GenerateMatrix(si, 1, 1);
Console.WriteLine("Generation finished.");
//

for (int y=0; y < l; y++){
Console.WriteLine("");
Console.WriteLine(new string('-',70));
for (int x=0; x < l; x++){
Console.Write("| " + ar[x,y].ToString().PadLeft(3) + " ");
}
}
Console.WriteLine("");
Console.WriteLine("");
Console.Write("Done.");
Console.Read();
}

Написать комментарий