- 最后登录
- 2022-11-17
- 在线时间
- 223 小时
- 阅读权限
- 20
- 注册时间
- 2008-8-14
- 积分
- 523
- 帖子
- 251
- 精华
- 1
- UID
- 40010
- 性别
- 保密
- 积分
- 523
- 帖子
- 251
- 精华
- 1
- UID
- 40010
- 性别
- 保密
|
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 Pai
{
public partial class FormSort : Form
{
List<List<int>> lli = new List<List<int>>();
public FormSort()
{
InitializeComponent();
}
private void FormSort_Load(object sender, EventArgs e)
{
lbMsg.Text = "";
tCount.Enabled = false;
bResult.Enabled = false;
}
private void bCalculate_Click(object sender, EventArgs e)
{
lli.Clear();
lbMsg.Text = "";
tResult.Clear();
bResult.Enabled = false;
tCount.Enabled = false;
List<int> d = new List<int>();
int len;
int i = 0;
try
{
if (string.IsNullOrEmpty(tNum.Text))
{
MessageBox.Show("请输入数组。");
return;
}
string[] arrStr = tNum.Text.Split(',');
foreach (string str in arrStr)
{
int num = Convert.ToInt32(str);
if (d.Count == 0)
d.Add(num);
else
{
if (num < d[0])
d.Insert(0, num);
else if (num > d[d.Count - 1])
d.Add(num);
else
{
for (i = 0; i < d.Count - 1; i++)
{
if (num > d[i] && num < d[i + 1])
{
d.Insert(i + 1, num);
break;
}
}
}
}
}
len = d.Count;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
List<int> tmp = new List<int>();
List<int> t = new List<int>();
for (i = 0; i < len; i++)
{
tmp.Add(0);
t.Add(d[i]);
}
int strCount = 0;
while (t.Count == d.Count)
{
bool bFound = false;
if (t.Count > 1)
{
for (i = 0; i < t.Count - 1; i++)
{
if (t[i] == 0 && Math.Abs(t[i + 1]) > 1 || t[i + 1] == 0 && Math.Abs(t[i]) > 1)
{
bFound = true;
break;
}
else if (t[i] - t[i + 1] < -1 || t[i] - t[i + 1] > 1)
{
if (gcd(t[i], t[i + 1]) > 1)
{
bFound = true;
break;
}
}
}
}
if (!bFound)
{
//lli.Add(t);
strCount++; |
|