Thuật toán lát gạch C#
Tạo file LatGach.INP trong thư mục Debug với nội dung: 2
Thuật toán lát gạch trong C#
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace LatGach
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Input
int n;
// Output
int[,] a;
int size;
int c = 1;
private void btnNhap_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader("LatGach.INP");
string s;
s = sr.ReadLine();
n = int.Parse(s);
size = 1 << n;
txtN.Text = n.ToString();
txtSize.Text = size.ToString();
a = new int[size + 1, size + 1];
a[1, 1] = 123;
Xuat();
}
void LatGach(int x, int y, int s, int k)
{
if (s == 2)
{
if (k != 1) a[x, y] = c;
if (k != 2) a[x, y + 1] = c;
if (k != 3) a[x + 1, y] = c;
if (k != 4) a[x + 1, y + 1] = c;
}
else
{
if (k == 2)
{
}
}
}
void Xuat()
{
txtGach.Text = "";
for (int i = 1; i <= size; i++)
{
string s = "";
for (int j = 1; j <= size; j++)
s = s + String.Format("{0, 5}", a[i,j]);
txtGach.Text += s + Environment.NewLine;
}
}
private void btnLatGach_Click(object sender, EventArgs e)
{
LatGach(1, 1, size, 4);
Xuat();
}
}
}
No comments :
Post a Comment