⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 给你4 个随机数
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
   v:=v1-v2;
   if v=res then
     list.Lines.Add(s1+'*'+s2+'-'+'('+s3+'-'+s4+')'+'='+s5);
   //  n1/n2-(n3-n4)
   v1:=n1/n2;
   v2:=n3-n4;
   v:=v1-v2;
   if v=res then
     list.Lines.Add(s1+'/'+s2+'-'+'('+s3+'-'+s4+')'+'='+s5);

//  #################
   //n1*(n2+n3)+n4
   v1:=n2+n3;
   v:=n1*v1+n4;
   if v=res then
     list.Lines.Add(s1+'*('+s2+'+'+s3+')+'+s4+'='+s5);
   //n1*(n2+n3)-n4
   v1:=n2+n3;
   v:=n1*v1-n4;
   if v=res then
     list.Lines.Add(s1+'*('+s2+'+'+s3+')-'+s4+'='+s5);
   //n1*(n2+n3)*n4
   v1:=n2+n3;
   v:=n1*v1*n4;
   if v=res then
     list.Lines.Add(s1+'*('+s2+'+'+s3+')*'+s4+'='+s5);

   //n1*(n2+n3)/n4
   v1:=n2+n3;
   v:=n1*v1/n4;
   if v=res then
     list.Lines.Add(s1+'*('+s2+'+'+s3+')/'+s4+'='+s5);

   //n1*(n2-n3)+n4
   v1:=n2-n3;
   v:=n1*v1-n4;
   if v=res then
     list.Lines.Add(s1+'*('+s2+'-'+s3+')+'+s4+'='+s5);

   //n1*(n2-n3)-n4
   v1:=n2-n3;
   v:=n1*v1-n4;
   if v=res then
     list.Lines.Add(s1+'*('+s2+'-'+s3+')-'+s4+'='+s5);

   //n1*(n2-n3)*n4
   v1:=n2-n3;
   v:=n1*v1*n4;
   if v=res then
     list.Lines.Add(s1+'*('+s2+'-'+s3+')*'+s4+'='+s5);

   //n1*(n2-n3)/n4
   v1:=n2-n3;
   v:=n1*v1-n4;
   if v=res then
     list.Lines.Add(s1+'*('+s2+'-'+s3+')/'+s4+'='+s5);

//##################
   //n1/(n2+n3)+n4
   v1:=n2+n3;
   v:=n1/v1+n4;
   if v=res then
     list.Lines.Add(s1+'/('+s2+'+'+s3+')+'+s4+'='+s5);
   //n1/(n2+n3)-n4
   v1:=n2+n3;
   v:=n1/v1-n4;
   if v=res then
     list.Lines.Add(s1+'/('+s2+'+'+s3+')-'+s4+'='+s5);

   //n1/(n2+n3)*n4
   v1:=n2+n3;
   v:=n1/v1*n4;
   if v=res then
     list.Lines.Add(s1+'/('+s2+'+'+s3+')*'+s4+'='+s5);

   //n1/(n2+n3)/n4
   v1:=n2+n3;
   v:=n1/v1/n4;
   if v=res then
     list.Lines.Add(s1+'/('+s2+'+'+s3+')/'+s4+'='+s5);

   //n1/(n2-n3)+n4
   v1:=n2-n3;
   if v1<>0 then
     begin
       v:=n1/v1-n4;
       if v=res then
         list.Lines.Add(s1+'*('+s2+'-'+s3+')+'+s4+'='+s5);
     end;
   //n1/(n2-n3)-n4
   v1:=n2-n3;
   if v1<>0 then
     begin
       v:=n1/v1-n4;
       if v=res then
         list.Lines.Add(s1+'*('+s2+'-'+s3+')-'+s4+'='+s5);
     end;

   //n1/(n2-n3)*n4
   v1:=n2-n3;
   if v1<>0 then
     begin
       v:=n1/v1*n4;
       if v=res then
         list.Lines.Add(s1+'*('+s2+'-'+s3+')*'+s4+'='+s5);
     end;
   //n1/(n2-n3)/n4
   v1:=n2-n3;
   if v1<>0 then
     begin
       v:=n1/v1/n4;
       if v=res then
         list.Lines.Add(s1+'*('+s2+'-'+s3+')/'+s4+'='+s5);
     end;
//1111111111111111111111111111111111
  //  (n1+n2)*(n3+n4)
  v1:=n1+n2;
  v2:=n3+n4;
  v:=v1*v2;
  if v=res then
      list.Lines.Add('('+s1+'+'+s2+')*('+s3+'+'+s4+')='+s5);

  //  (n1+n2)*(n3-n4)
  v1:=n1+n2;
  v2:=n3-n4;
  v:=v1*v2;
  if v=res then
      list.Lines.Add('('+s1+'+'+s2+')*('+s3+'-'+s4+')='+s5);

  //  (n1+n2)/(n3+n4)
  v1:=n1+n2;
  v2:=n3+n4;
  v:=v1/v2;
  if v=res then
      list.Lines.Add('('+s1+'+'+s2+')/('+s3+'+'+s4+')='+s5);

  //  (n1+n2)/(n3-n4)
  v1:=n1+n2;
  v2:=n3-n4;
  if v2<>0 then
    begin
      v:=v1/v2;
      if v=res then
        list.Lines.Add('('+s1+'+'+s2+')/('+s3+'-'+s4+')='+s5);
   end;
//2222222222222222222222222222
  //  (n1-n2)*(n3+n4)
  v1:=n1-n2;
  v2:=n3+n4;
  v:=v1*v2;
  if v=res then
      list.Lines.Add('('+s1+'-'+s2+')*('+s3+'+'+s4+')='+s5);

  //  (n1-n2)*(n3-n4)
  v1:=n1-n2;
  v2:=n3-n4;
  v:=v1*v2;
  if v=res then
      list.Lines.Add('('+s1+'-'+s2+')*('+s3+'-'+s4+')='+s5);

  //  (n1-n2)/(n3+n4)
  v1:=n1-n2;
  v2:=n3+n4;
  v:=v1/v2;
  if v=res then
      list.Lines.Add('('+s1+'-'+s2+')/('+s3+'+'+s4+')='+s5);

  //  (n1-n2)/(n3-n4)
  v1:=n1-n2;
  v2:=n3-n4;
  if v2<>0 then
    begin
      v:=v1/v2;
      if v=res then
       list.Lines.Add('('+s1+'-'+s2+')/('+s3+'-'+s4+')='+s5);
   end;


end;


//把输入edit1,edit2,edit3,edit4,中的四个数的所有排列组合保存到memo1中.
procedure TForm1.Button1Click(Sender: TObject);
var
str,str2:array[1..4] of string;
S,S1,S2,S3,temp:string;
i,j,count,index:integer;
flag:boolean;
begin

memo1.Lines[0]:=edit1.Text+'_'+edit2.Text+'_'+
                edit3.Text+'_'+edit4.Text+'_';
s:=memo1.Lines[0];
for index:=0 to 13 do
 begin
  s1:=s;
  s2:='';
  count:=0;
  for i:=1 to 50 do
    begin
      if s1[i]<>'_' then
         s2:=s2+s1[i]
      else
        begin
          count:=count+1;
          str[count]:=s2;
          s2:='';
          if count=4 then break;
        end;
     end;

   for i:=1 to 3 do
     begin
       flag:=false;
       str2:=str;
       //str[1]与str[i+1]交换
       temp:=str2[1];
       str2[1]:=str2[i+1];
       str2[i+1]:=temp;

       s3:=str2[1]+'_'+str2[2]+'_'+str2[3]+'_'+str2[4]+'_';
       //检查s3是否与memo1中的有相同,如果不同,就把s3添加上去
       for j:=0 to memo1.Lines.Count-1 do
           if s3=memo1.Lines[j] then flag:=true;
       if flag <>true then
          memo1.Lines.Add(s3);

     end;
     s:=memo1.Lines[index+1];
     if s='' then break;

 end;

end;

procedure TForm1.Button2Click(Sender: TObject);
var
index,count,i:integer;
s1,s2:string;
str:array[1..4] of string;
begin
  MmList1.Lines.Add('答案如下:');
  Mmlist1.Lines.Add('-----------------');
  for index:=0 to memo1.Lines.Count-1 do
     begin
       s1:=memo1.Lines[index];
       s2:='';
       count:=0;
       for i:=1 to 100 do
         begin
          if s1[i]<>'_' then
            s2:=s2+s1[i]
          else
            begin
              count:=count+1;
              str[count]:=s2;
              s2:='';
              if count=4 then break;
           end;
       end;
       //下面这句中的(EdNumber.text)的默认值是24 ,不过你可以成26,那就是26点游戏了,
       YunSuan(StrToFloat(str[1]),strToFloat(str[2]),strToFloat(str[3]),strToFloat(str[4]),StrToFloat(EdNumber.Text),MmList1);
       YunSuan2(StrToFloat(str[1]),strToFloat(str[2]),strToFloat(str[3]),strToFloat(str[4]),StrToFloat(EdNumber.Text),MmList2);
     end;
   // 把Mmlist2中的答案复制到Mmlist1中.
   for i:=0 to MmList2.Lines.Count-1 do
     begin
       MmList1.Lines.Add(MmList2.Lines[i]);
       MmList1.Lines.Add('------------------------------');
     end;

end;

procedure TForm1.Button3Click(Sender: TObject);
begin
//检查输入的四个数中没有一个是空的
if (length(edit1.Text)<>0 ) and
   (length(edit2.text)<>0 ) and
   (length(edit3.text)<>0 ) and
   (length(edit4.text)<>0 ) and
//确保输入的四个数都不为'0'
   (strToFloat(edit1.Text)<>0) and
   (strToFloat(edit2.Text)<>0) and
   (strToFloat(edit3.Text)<>0) and
   (strToFloat(edit4.text)<>0) then
   begin
    memo1.Clear;
    MmList1.Clear;
    MmList2.Clear;
    button1.Click;
    button2.Click;
   end
 else
   showMessage('你是否忘记输入某个数据了,或是某个数据为 0 了!');
end;

procedure TForm1.BtCloseClick(Sender: TObject);
begin
 form1.Close;
end;
//以下是实现计算器的输入功能
procedure TForm1.BTnToBTn9Click(Sender: TObject);
var
  postion:integer;//保存要插入的位置,即光标当前光标的位置
  s,s1:string;
begin
  postion:=EdLcd.SelStart+1;
  s:=EdLcd.Text;
  //选择替换
  if EdLcd.SelLength<>0 then
  delete(s,postion,edlcd.SelLength);
  s1:=(sender as Tbutton).Caption;
  insert(s1,s,postion);
  EdLcd.Text:=s;
  EdLcd.SelStart:=length(EdLcd.Text)+1;

end;

procedure TForm1.btOKClick(Sender: TObject);
var
i:integer;
flag:boolean;
s:string;
begin
  button3.Click;
  flag:=false;
  s:=EdLCD.Text+'='+EdNumber.text;

  //检查你在EdLCD中输入的字符串是否包含于第一答案列表Mmlist1中,如果在其中,则说明你输入的答案是正确的.
  for i:=0 to MmList1.Lines.Count-1 do
     if s=Mmlist1.Lines[i] then flag:=true;
     
  if flag=true then
     begin
       //提示你,你答对了.
       LbShow.Caption:='哈哈:'+#10+#13+'小猪真聪明 !!!';
       LbShow.Visible:=True;
     end
  else
     begin
        //提示你,你答错了.
        LbShow.Caption:='哈哈:'+#10+#13+'小猪要加油啊!!!';
        LbShow.Visible:=True;
     end;
end;

procedure TForm1.btClrClick(Sender: TObject);
begin
  EdLCD.Text:='';
end;

procedure TForm1.btChongLeiClick(Sender: TObject);
var
StrTime,subStr:string;
number:integer;
begin
//随机产生4个10以内的数
   StrTime:=TimeToStr(now());

   subStr:=copy(StrTime,length(StrTime)-1,2);
   number:=StrToInt(subStr) mod 10;
 

   if number <5 then
    number:=number+4;

   edit1.Text:=intToStr(random(number)+1);
   edit2.Text:=intToStr(random(number)+1);
   edit3.Text:=intToStr(random(number)+1);
   edit4.Text:=intToStr(random(number)+1);

//清空所有内容
  EdLCD.Text:='';

  MmList1.Clear;
  MmList2.Clear;
  memo1.Clear;

  LbShow.Visible:=false;
  Mmlist1.Visible:=false;


end;

procedure TForm1.btShowClick(Sender: TObject);
begin
button3.Click;
Mmlist1.Visible:=true;
end;

procedure TForm1.BtAboutClick(Sender: TObject);
begin
  FmAbout.Show;
end;

procedure TForm1.btnBackSpaceClick(Sender: TObject);
var
postion:integer;
s:string;
begin
  s:=EdLcd.Text;
  postion:=EdLcd.SelStart;
  delete(s,postion,1);
  EdLcd.Text:=s;
  EdLcd.SelStart:=postion-1;


end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  btChongLei.Click;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -