我知道了,也已完成部分程序,见下面。
但这样拿分太容易啦!
再给点突破性建议吧!Leechange肯定石油分得啦
unit Utest;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Mask, ComCtrls;
type
TFmtest1 = class(TForm)
Lbtest1: TLabel;
btbtest2: TBitBtn;
Lbtest2: TLabel;
btbtest1: TBitBtn;
procedure btbtest2Click(Sender: TObject);
procedure cuttext(str:string;fieldLen:integer;var strList:TStringlist);
procedure Edtest1Change(Sender: TObject);
procedure btbtest1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Fmtest1: TFmtest1;
s:string;
testtext:textfile;
arrEd:array[0..100] of TRichEdit;
arrEd1:array[0..1] of TEdit;
arrLb:array[0..100] of TLabel;
arrLb1:array[0..2] of TLabel;
implementation
{$R *.DFM}
procedure TFmtest1.btbtest2Click(Sender: TObject);
var s:textfile;
f:string;
mylist:TStringlist;
k,j,i:integer;
btb:TBitbtn;
begin
k:=0;
fmtest1.btbtest2.Visible:=false;
fmtest1.btbtest2.Visible:=false;
mylist:=Tstringlist.Create;
fmtest1.Lbtest2.Visible:=false;
assignfile(s,'d:/test/first1.txt');
reset(s);
readln(s,f);
cuttext(f,68,mylist);
if (length(f) mod 68)<>0 then
i:=length(f) div 68
else
i:=(length(f) div 68)+1;
for j:=0 to i do
begin
k:=k+j*24;
arrLb[j]:=TLabel.create(nil);
arrLb[j].Parent:=fmtest1;
arrLb[j].Left:=0;
arrLb[j].Width:=569;
arrLb[j].Height:=24;
arrLb[j].Top:=32+j*48;
arrLb[j].Caption:=mylist.Strings[j];
end;
mylist.Free;
for j:=0 to i do
begin
arrEd[j]:=TRichEdit.create(nil);
arrEd[j].parent:=fmtest1;
arrEd[j].left:=0;
arrEd[j].width:=569;
arrEd[j].height:=24;
arrEd[j].top:=(17+j*48);
arrEd[j].OnChange:=Edtest1Change;
end;
btb:=TBitbtn.Create(nil);
btb.Parent:=fmtest1;
btb.Left:=435;
btb.Width:=75;
btb.Height:=24;
btb.Kind:=bkOK;
btb.Caption:='提交';
btb.Top:=k div 2;
btb.OnClick:=btbtest1Click;
for i:=0 to 2 do
begin
arrLb1
:=TLabel.Create(nil);
arrLb1.Parent:=fmtest1;
arrLb1.Top:=k div 2;
arrLb1.Height:=24;
end;
arrLb1[0].Left:=0;
arrLb1[0].Caption:='错误数:';
arrLb1[0].Width:=64;
arrLb1[1].Left:=104;
arrLb1[1].Width:=64;
arrLb1[1].Caption:='正确率:';
arrLb1[2].Left:=216;
arrLb1[2].Width:=16;
arrLb1[2].Caption:='%';
for i:=0 to 1 do
begin
arrEd1:=TEdit.Create(nil);
arrEd1.Parent:=fmtest1;
arrEd1.Top:=k div 2;
arrEd1.Height:=18;
end;
arrEd1[0].Left:=56;
arrEd1[0].Width:=33;
arrEd1[1].Left:=165;
arrEd1[1].Width:=41;
end;
procedure Tfmtest1.cuttext(str:string;fieldlen:integer;var strlist:Tstringlist);
var l,len:integer;
t:string;
function loadword(var w:string):integer;
begin
if l<=len then
begin
if ord(str[l])<128 then
begin//如果是数字或字母
w:=str[l];
l:=l+1;
result:=1;
exit;
end
else
begin
if ((l+1)<=len) and (ord(str[l+1])>=128) then
begin//如果是中文
w:=copy(str,l,2);
l:=l+2;
result:=2;
exit;
end
else
begin
result:=0;
exit;
end;
end;
end
else
result:=0;
end;
function loadstring:string;
var w:string;
wlen:integer;
retlen:integer;
begin
retlen:=0;
result:='';
wlen:=loadword(w);
while wlen>0 do
begin
if (retlen+wlen)>fieldlen then
begin
l:=l-wlen;
exit;
end;
result:=result+w;
retlen:=retlen+wlen;
if retlen=fieldlen then
exit;
wlen:=loadword(w);
end;
end;
begin
strlist.Clear;
l:=1;
len:=length(str);
t:=loadstring;
while t<>'' do
begin
strlist.add(chr(13)+chr(10)+t);
t:=loadstring;
end;
end;
procedure TFmtest1.Edtest1Change(Sender: TObject);
var i,l,k,h,g:integer;
m,s:string;
f:textfile;
begin
m:='';
assignfile(f,'d:/test/first1.txt');
reset(f);
readln(f,s);
l:=length(s);
if (l mod 68)<>0 then
k:=(l div 68)+1
else
k:=l div 68;
for i:=0 to k do
begin
m:=arrEd.Text;
h:=length(m);
for g:=1 to (h div 2) do
begin
if (m[2*g-1]+m[2*g])<>(s[2*g-1]+s[2*g]) then
begin
arrEd.SelStart:=2*g-1;
arrEd.SelLength:=2;
arrEd.SelAttributes.Color:=clred;
arrEd.SelStart:=2*g+1;
end;
if (m[2*g-1]+m[2*g])=(s[2*g-1]+s[2*g]) then
begin
arred.SelStart:=2*g-1;
arrEd.SelLength:=2;
arrEd.SelAttributes.Color:=clblack;
arred.SelStart:=2*g+1;
end;
end;
delete(s,1,h);
end;
end;
procedure TFmtest1.btbtest1Click(Sender: TObject);
var h,k,l,j,i:integer;
x,m,n:string;
s:textfile;
begin
m:='';
assignfile(s,'d:/test/first1.txt');
reset(s);
readln(s,n);
j:=length;
if (j mod 68)<>0 then
k:=(j div 68)+1
else
k:=j div 68;
for i:=0 to k-1 do
m:=m+arrEd.Text;
l:=length;
h:=0;
for i:=1 to (l div 2) do
if (m[2*i-1]+m[2*i])<>(n[2*i-1]+n[2*i]) then
begin
inc(h);
end;
x:=inttostr(h);
arrEd1[0].Text:=x;
arrEd1[1].Text:=inttostr((1-(h div(l div 2)))*100);
end;
end.