zssmoa
سه شنبه 13 دی 1390, 20:15 عصر
سلام دوستان
خدا خیر بده به کسی که ایراد این کد رو به من بگه هر کاریش کردم حل نشد
با consol نوشتم یه error میده نمی دونم چیه
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numeric;
namespace ConsoleApplication1
{
public class queen
{
public int w=0,h=0, k=0;
public int [,] a=new int[4,4];
public int count;
// *****************Fbase**************
public void Fbase()
{
for (int i = 0; i <= 4; i++)
for (int j = 0; j <= 4; j++)
a[i, j] = 0;
count = 0;
}
// ***************SetFirst**************
public void SetFirst(int i, int j)
{
int x; int y;
count = count + 1;
x = i - 1; y = j;
while (x > 0)
{ a[x, y] = 1; x--; }
x = i - 1; y = j + 1;
while (x >= 0 && y <= 4)
{ a[x, y] = 1; x--; y++; }
x = i + 1; y = j - 1;
while (y >= 0 && x <= 4)
{ a[x, y] = 1; x++; y--; }
x = i - 1; y = j - 1;
while (x >= 0 && y >= 0)
{ a[x, y] = 1; x--; y--; }
x = i + 1; y = j;
while (x <= 4)
{ a[x, y] = 1; x++; }
x = i + 1; y = j + 1;
while (x <= 4 && y <= 4)
{ a[x, y] = 1; x++; y++; }
x = i; y = j - 1;
while (y >= 0)
{ a[x, y] = 1; y--; }
x = i; y = j + 1;
while (y <= 4)
{ a[x, y] = 1; y++; }
}
//*******************FindNext*****************
public void FindNext()
{
for (int i = 0; i <= 4; i++)
for (int j = 0; j <= 4; j++)
if (a[i, j] == 0)
SetFirst(i, j);
}
//*****************Show*********************
public void Show()
{
for (int i = 0; i <= 4; i++)
for (int j = 0; j <= 4; j++)
Console.WriteLine(a[i, j]);
Console.WriteLine("queen=" + count);
}
//*******************************************
static void Main()
{
for (w = 0; w <= 4; w++)
for (h = 0; h <= 4; h++)
{
Fbase();
a[w, h] = 2;
SetFirst(w, h);
FindNext();
Show();
}
}
}
}
ممنون
خدا خیر بده به کسی که ایراد این کد رو به من بگه هر کاریش کردم حل نشد
با consol نوشتم یه error میده نمی دونم چیه
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numeric;
namespace ConsoleApplication1
{
public class queen
{
public int w=0,h=0, k=0;
public int [,] a=new int[4,4];
public int count;
// *****************Fbase**************
public void Fbase()
{
for (int i = 0; i <= 4; i++)
for (int j = 0; j <= 4; j++)
a[i, j] = 0;
count = 0;
}
// ***************SetFirst**************
public void SetFirst(int i, int j)
{
int x; int y;
count = count + 1;
x = i - 1; y = j;
while (x > 0)
{ a[x, y] = 1; x--; }
x = i - 1; y = j + 1;
while (x >= 0 && y <= 4)
{ a[x, y] = 1; x--; y++; }
x = i + 1; y = j - 1;
while (y >= 0 && x <= 4)
{ a[x, y] = 1; x++; y--; }
x = i - 1; y = j - 1;
while (x >= 0 && y >= 0)
{ a[x, y] = 1; x--; y--; }
x = i + 1; y = j;
while (x <= 4)
{ a[x, y] = 1; x++; }
x = i + 1; y = j + 1;
while (x <= 4 && y <= 4)
{ a[x, y] = 1; x++; y++; }
x = i; y = j - 1;
while (y >= 0)
{ a[x, y] = 1; y--; }
x = i; y = j + 1;
while (y <= 4)
{ a[x, y] = 1; y++; }
}
//*******************FindNext*****************
public void FindNext()
{
for (int i = 0; i <= 4; i++)
for (int j = 0; j <= 4; j++)
if (a[i, j] == 0)
SetFirst(i, j);
}
//*****************Show*********************
public void Show()
{
for (int i = 0; i <= 4; i++)
for (int j = 0; j <= 4; j++)
Console.WriteLine(a[i, j]);
Console.WriteLine("queen=" + count);
}
//*******************************************
static void Main()
{
for (w = 0; w <= 4; w++)
for (h = 0; h <= 4; h++)
{
Fbase();
a[w, h] = 2;
SetFirst(w, h);
FindNext();
Show();
}
}
}
}
ممنون