| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
界面做的那个丑.哈! 
 
unit Unit1; 
interface 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, Grids, Buttons; 
type 
  TForm1 = class(TForm) 
    Edit1: TEdit; 
    BitBtn1: TBitBtn; 
    table1: TStringGrid; 
    Button1: TButton; 
    Label1: TLabel; 
    Label2: TLabel; 
    Label3: TLabel; 
    Label4: TLabel; 
    Button2: TButton; 
    Label5: TLabel; 
    Label6: TLabel; 
    procedure BitBtn1Click(Sender: TObject); 
    procedure Button1Click(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
var 
  Form1: TForm1; n:Integer; num:array[1..100] of Integer; 
implementation 
{$R *.dfm} 
procedure TForm1.BitBtn1Click(Sender: TObject); 
var 
  temp1,temp,str:string; 
  k,I,J:Integer; 
begin 
  str:=trim(edit1.text);         //trim 去除字符串两边的空格 LTRIM 去除左边空格 RTRIM 去除右边空格 
  k:=Length(str);                //LENGTH 返回字符串长度 索引从1开始 
  label1.caption:='字符串长度='+INTTOSTR(K); 
  I:=1; 
  n:=1; 
  while I<=K do 
    begin 
     IF str[I]<>#32 THEN       //直接调用数组的方式 STR[I] 
        begin 
          TEMP:=TEMP+STR[I]; 
          temp1:=TEMP1+STR[I]; 
            begin 
             if str[i+1]=#32 then 
               num[n]:=StrToInt(temp); 
             if i=k then 
               num[n]:=StrToInt(temp); 
             end 
        end 
     ELSE 
       IF str[I+1]=#32 THEN    //查找下一个是不是空格,如果是空格继续查找 直到不是空格 
        begin 
          I:= I+0; 
        END 
       else 
        begin 
         num[n]:=StrToInt(temp); 
         n:=n+1; 
         TEMP1:=TEMP1+' '; 
         TEMP:=''; 
        end; 
     I:=I+1; 
     table1.Cells[0,n-1]:=inttostr(NUM[n]) ; 
     Label2.CAPTION:=temp1; 
 
    end; 
 
end; 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
Edit1.Text:=''; 
label1.caption:='字符串长度='; 
Label2.Caption:='零'; 
end; 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
table1.Visible:=false; 
end; 
procedure TForm1.Button2Click(Sender: TObject); 
var 
l,j,k,m:Integer; 
begin 
  for l:=1 to n-1 do 
    begin 
      k:=n-l; 
       for j:=1 to k do 
        begin 
          if num[j]<num[j+1] then 
            begin 
              m:=num[j]       ; 
              NUM[j]:=num[j+1] ; 
              NUM[j+1]:=m; 
            end; 
        end; 
    end; 
    Label6.caption:=''; 
    for l:=n downto 1 do 
    Label6.caption:=Label6.caption+' ' +inttostr(NUM[l])+' '; 
end; 
end. 
 |   
 
 
 
 |