/******************************************************************************
Online C# Compiler.
Code, Compile, Run and Debug C# program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Hello World");
//1
Q1 q1 = new Q1(8);
//q1.BuildNotOk();
q1.BuildOk();
q1.Print();
bool b = q1.isOk();
Console.WriteLine();
Console.WriteLine("b:{0}", b);
//2
//Q2 q2 = new Q2();
//q2.Test();
}
}
using System;
public class Q1
{
private int[,] array;
public Q1(int n)
{
this.array = new int[n, n];
}
public Q1(int n, int m)
{
this.array = new int[n, m];
}
public void BuildOk()
{
for (int i = 0; i < this.array.GetLength(0); i++)
{
for (int j = 0; j < this.array.GetLength(1); j++)
{
if (i == j)
this.array[i, j] = 3;
else if (i < j)
this.array[i, j] = 5;
else
this.array[i, j] = 7;
}
}
}
public void BuildNotOk()
{
Random rd = new Random();
int n = this.array.GetLength(0);
for (int i = 0; i < this.array.GetLength(0); i++)
{
for (int j = 0; j < this.array.GetLength(1); j++)
{
this.array[i, j] = rd.Next(n);
}
}
}
public void Print()
{
for (int i = 0; i < this.array.GetLength(0); i++)
{
for (int j = 0; j < this.array.GetLength(1); j++)
{
Console.Write("{0}, ",this.array[i, j]);
}
Console.WriteLine();
}
}
public bool isOk()
{
for (int i = 0; i < this.array.GetLength(0); i++)
{
for (int j = 0; j < this.array.GetLength(1); j++)
{
if (i == j)
if (this.array[i, j] != 3)
return false;
else if (i < j)
if (this.array[i, j] != 5)
return false;
else
if (this.array[i, j] != 7)
return false;
}
}
return true;
}
}
using System;
public class Q2
{
private int[] array= { 3, 4, 9, 7, 12, 8, 30, 6, 8, 11, 3, 99, 5 };
public Q2()
{
this.Print();
}
public void Test()
{
int val = 0;
int count = 0;
while (array[val] >= 0 && array[val] < array.Length)
{
count++;
Console.WriteLine("array[{0}] = {1}", val,array[val]);
val = array[val];
}
Console.WriteLine("array[] = {0}", array[val]);
Console.WriteLine("count:{0}", count);
}
public void Print()
{
for (int i = 0; i < array.Length; i++)
{
Console.Write("{0}| ", i);
}
Console.WriteLine();
for (int i = 0; i < array.Length; i++)
{
Console.Write("{0}| ",array[i]);
}
Console.WriteLine();
}
}