如题:
a,b,c,d为变量,A为常量。a,b,c,d的取值在1-36(均可等)之间
表达式为a+b+c+d=A,a!=b,b!=c,c!=d
已知A,现任意随机出一组a,b,c,d
举个栗子:
A=72
a=24,b=14,c=5,d=29
...
不可以是
a=24,b=24,c=18,d=6
...
如题:
a,b,c,d为变量,A为常量。a,b,c,d的取值在1-36(均可等)之间
表达式为a+b+c+d=A,a!=b,b!=c,c!=d
已知A,现任意随机出一组a,b,c,d
举个栗子:
A=72
a=24,b=14,c=5,d=29
...
不可以是
a=24,b=24,c=18,d=6
...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int GetAnswer(int end)
{
int num;
Random random = new Random();
num = random.Next(end);
return num;
}//得到随机数字
private bool IsSame(int num_1,int num_2,int num_3,int num_4)
{
bool rtn = false;
ArrayList list = new ArrayList();
list.Add(num_1);
list.Add(num_2);
list.Add(num_3);
list.Add(num_4);
for (int i = 0; i <= list.Count-1;i++)
{
for (int j = i+1; j <= list.Count-1; j++)
{
if (list[i] == list[j])
{
rtn = false;
}
else
{
rtn = true;
}
}
}
return rtn;
}//判断是否有重复
private void GetRight()
{
int anum, bnum, cnum, dnum;
anum = GetAnswer(Convert.ToInt16(txtA.Text));
bnum = GetAnswer(Convert.ToInt16(txtA.Text)-anum);
cnum = GetAnswer(Convert.ToInt16(txtA.Text) - anum-bnum);
dnum = Convert.ToInt16(txtA.Text) - anum - bnum-cnum;
if(IsSame(anum,bnum,cnum,dnum))
{
lbla.Text = anum.ToString();
lblb.Text = bnum.ToString();
lblc.Text = cnum.ToString();
lbld.Text = dnum.ToString();
}
else
{
anum = GetAnswer(Convert.ToInt16(txtA.Text));
bnum = GetAnswer(anum);
cnum = GetAnswer(bnum);
dnum = Convert.ToInt16(txtA.Text) - anum - bnum - cnum;
}
lbla.Text=anum.ToString();
lblb.Text=bnum.ToString();
lblc.Text=cnum.ToString();
lbld.Text=dnum.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if (txtA.Text == "" || txtA.Text == null)
{
MessageBox.Show("请输入数据A!");
txtA.Focus();
}
else
{
GetRight();
}
}
}
}
没有看到“a,b,c,d的取值在1-36(均可等)” 这个条件 其他的 都还好 要是需要原工程加我qq1101559491