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;
namespace SparseNew
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const int Row = 3;
const int Hight = 2;
int[,] Integer1 = new int[Row, Hight];
int[,] Integer2 = new int[Row, Hight];
int[,] IntegerAdd = new int[Row, Hight];
int i = 0; int j = 0;
//===============================================================================================================================
private void txt_EnterInteger1_KeyPress(object sender, KeyPressEventArgs e)//Enter1:True
{
if (e.KeyChar == '\r')
{
Integer1[i, j] = Convert.ToInt32(txt_EnterInteger1.Text);
if (j < Hight)
{
j++;
lbl_EnterInteger1.Text += txt_EnterInteger1.Text + " ";
txt_EnterInteger1.Text = "";
}
if (j == Hight && i < Row)
{
j = 0;
i++;
lbl_EnterInteger1.Text += txt_EnterInteger1.Text + "\r\n\r\n";
}
if (i == Row && j == 0)
{
MessageBox.Show("Thanks...");
i = 0;
txt_EnterInteger1.Enabled = false;
}
}
}
public void Sparse1(int[,] NumberOne)//Sparse1:True
{
int counter1 = 0; int xyz1 = 0; int xyzT1 = 0;
for (int a1 = 0; a1 < Row; a1++)
for (int b1 = 0; b1 < Hight; b1++)
if (NumberOne[a1, b1] != 0)
counter1++;
int[,] NewCapacity1 = new int[counter1, 3];
int[,] NewCapacityT1 = new int[ counter1,3];
for (int a1 = 0; a1 < Row ; a1++)
for (int b1 = 0; b1 < 2; b1++)
{
if (NumberOne[a1, b1] != 0)
{
NewCapacity1[xyz1, 0] = a1;
NewCapacity1[xyz1, 1] = b1;
NewCapacity1[xyz1, 2] = NumberOne[a1, b1];
lbl_Sparse1.Text += "RowS1:" + NewCapacity1[xyz1, 0] + " " + "HightS1:" + NewCapacity1[xyz1, 1] + " " + "IntegerS1:" + NewCapacity1[xyz1, 2] + "\r\n\r\n";
xyz1++;
NewCapacityT1[xyzT1,0] = b1;
NewCapacityT1[xyzT1,1] = a1;
NewCapacityT1[xyzT1,2] = NumberOne[a1,b1];
lbl_SparseT1.Text += "RowST1:" + NewCapacityT1[xyzT1, 0] + " " + "HightST1:" + NewCapacityT1[xyzT1, 1] + " " + "IntegerST1:" + NewCapacityT1[xyzT1, 2] + "\r\n\r\n";
xyzT1++;
}
}
}
//==============================================================================================================================
private void txt_EnterInteger2_KeyPress(object sender, KeyPressEventArgs e)//Enter2:True
{
if (e.KeyChar == '\r')
{
Integer2[i, j] = Convert.ToInt32(txt_EnterInteger2.Text);
if (j < Hight)
{
j++;
lbl_EnterInteger2.Text += txt_EnterInteger2.Text + " ";
txt_EnterInteger2.Text = "";
}
if (j == Hight && i < Row)
{
j = 0;
i++;
lbl_EnterInteger2.Text += txt_EnterInteger2.Text + "\r\n\r\n";
}
if (i == Row && j == 0)
{
MessageBox.Show("Thanks...");
i = 0;
txt_EnterInteger2.Enabled = false;
}
}
}
public void Sparse2(int[,] NumberTwo)//Sparse2:True
{
int counter2 = 0; int xyz2 = 0; int xyzT2 = 0;
for (int a2 = 0; a2 < Row; a2++)
for (int b2 = 0; b2 < Hight; b2++)
if (NumberTwo[a2, b2] != 0)
counter2++;
int[,] NewCapacity2 = new int[counter2, 3];
int[,] NewCapacityT2 = new int[ counter2,3];
for (int a2 = 0; a2 < Row; a2++)
for (int b2 = 0; b2 < 2; b2++)
{
if (NumberTwo[a2, b2] != 0)
{
NewCapacity2[xyz2, 0] = a2;
NewCapacity2[xyz2, 1] = b2;
NewCapacity2[xyz2, 2] = NumberTwo[a2, b2];
lbl_Sparse2.Text += "RowS2:" + NewCapacity2[xyz2, 0] + " " + "HightS2:" + NewCapacity2[xyz2, 1] + " " + "IntegerS2:" + NewCapacity2[xyz2, 2] + "\r\n\r\n";
xyz2++;
NewCapacityT2[xyzT2, 0] = b2;
NewCapacityT2[xyzT2, 1] = a2;
NewCapacityT2[xyzT2, 2] = NumberTwo[a2, b2];
lbl_SparseT2.Text += "RowST2:" + NewCapacityT2[xyzT2, 0] + " " + "HightST2:" + NewCapacityT2[xyzT2, 1] + " " + "IntegerST2:" + NewCapacityT2[xyzT2, 2] + "\r\n\r\n";
xyzT2++;
}
}
}
//================================================================================================================================
public void Add(int[,] NUMBERone, int[,] NUMBERtwo, int[,] NUMBERthree)//SparseAdd:True
{
for (int aAdd = 0; aAdd < Row; aAdd++)
for (int bAdd = 0; bAdd < Hight; bAdd++)
{
NUMBERthree[aAdd, bAdd] = NUMBERone[aAdd, bAdd] + NUMBERtwo[aAdd, bAdd];
lbl_Add.Text += "RowAdd:" + aAdd + " " + "HightAdd:" + bAdd + " " + "IntegerAdd:" + NUMBERthree[aAdd, bAdd] + "\r\n\r\n";
}
}
public void SparseAdd(int[,] NumberAdd)
{
int counter = 0; int xyz = 0; int xyzAddT = 0;
for (int SpA = 0; SpA < Row; SpA++)
for (int SpB = 0; SpB < Hight; SpB++)
if (NumberAdd[SpA, SpB] != 0)
counter++;
int[,] CapacityAdd = new int[counter, 3];
int[,] CapacityAddT = new int[counter ,3];
for (int Spa = 0; Spa < Row; Spa++)
for (int Spb = 0; Spb < 2; Spb++)
{
if (NumberAdd[Spa, Spb] != 0)
{
CapacityAdd[xyz, 0] = Spa;
CapacityAdd[xyz, 1] = Spb;
CapacityAdd[xyz, 2] = NumberAdd[Spa, Spb];
lbl_SparseAdd.Text += "RowAddS:" + CapacityAdd[xyz, 0] + " " + "HightAddS:" + CapacityAdd[xyz, 1] + " " + "IntegerAddS:" + CapacityAdd[xyz, 2] + "\r\n\r\n";
xyz++;
CapacityAddT[xyzAddT, 0] = Spb;
CapacityAddT[xyzAddT, 1] = Spa;
CapacityAddT[xyzAddT, 2] = NumberAdd[Spa, Spb];
lbl_SparseAddT.Text += "RowAddST:" + CapacityAddT[xyzAddT, 0] + " " + "HightAddST:" + CapacityAddT[xyzAddT, 1] + " " + "IntegerAddST:" + CapacityAdd[xyzAddT, 2] + "\r\n\r\n";
xyzAddT++;
}
}
}
//================================================================================================================================
private void Form1_Load(object sender, EventArgs e)
{
lbl_EnterInteger1.Text = "";
lbl_EnterInteger2.Text = "";
lbl_Sparse1.Text = "";
lbl_Sparse2.Text = "";
lbl_Add.Text = "";
lbl_SparseAdd.Text = "";
lbl_SparseT1.Text = "";
lbl_SparseT2.Text = "";
lbl_SparseAddT.Text = "";
}
private void btn_ClickShow_Click_1(object sender, EventArgs e)
{
Sparse1(Integer1);
Sparse2(Integer2);
Add(Integer1, Integer2, IntegerAdd);
SparseAdd(IntegerAdd);
}
}
}
علاقه مندی ها (Bookmarks)