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 二元关系判定
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click( object sender, EventArgs e)
{
textBox1.Text = "";
}
private int arr()
{
string text1 = textBox1.Text;
string[] result = System.Text.RegularExpressions.Regex.Split(text1, "\r\n");
string[] ss = System.Text.RegularExpressions.Regex.Split(result[0], ",");
return result.Length;
}
private double[,] read()
{
string text1 = textBox1.Text;
double[,] resultArray;
string[] result = System.Text.RegularExpressions.Regex.Split(text1, "\r\n");
string[] ss = System.Text.RegularExpressions.Regex.Split(result[0], ",");
resultArray= new double[result.Length,ss.Length];
if (result.Length != ss.Length)
{
return resultArray;
}
int i = 0, j = 0;
foreach ( string str in result)
{
string[] res = System.Text.RegularExpressions.Regex.Split(str, ",");
foreach ( string re in res)
{
resultArray[i, j] = Convert.ToDouble(re);
j++;
}
i++;
j = 0;
}
return resultArray;
}
private void button1_Click( object sender, EventArgs e)
{
try
{
double[,] result = read();
if (result.Length == 0)
{
MessageBox.Show( "输入的矩阵错误!");
}
foreach ( double i in result)
{
if (i != 1 && i != 0)
{
MessageBox.Show( "输入数字有误!", "提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
ClassDuality cd = new ClassDuality();
string res = "该矩阵有以下性质:\n";
if (cd.zifan(result,arr()) == 1)
{
res = res + "1、自反的\n";
}
else if (cd.zifan(result,arr()) == 0)
{
res = res + "1、反自反的\n";
}
else if (cd.zifan(result,arr()) == -1)
{
res = res + "1、既不是自反的也不是反自反的\n";
}
if (cd.duichen(result,arr()) == 1)
{
res = res + "2、既是对称又是反对陈的\n";
}
else if (cd.duichen(result,arr()) == 2)
{
res = res + "2、对称的\n";
}
else if (cd.duichen(result,arr()) == 3)
{
res = res + "2、反对称的\n";
}
else if (cd.duichen(result,arr()) == 0)
{
res = res + "2、既不是对称的又不是反对称的\n";
}
if (cd.chuandi(result,arr()) == 1)
{
res = res + "3、传递的\n";
}
else if (cd.chuandi(result,arr()) == 0)
{
res = res + "4、非传递的";
}
MessageBox.Show(res, "二元关系性质",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch
{
MessageBox.Show( "输入错误字符!", "提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
}