📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask,unit2;
type
Prorecord=record //-------------中间存储记录
userid:shortstring;
pid:shortstring;
yorn:boolean;
antimes:word;
alltimes:integer;
end;
type
Rplayersort=record //---------------结果记录
userid:shortstring; // 选手编号
pnum:word; // 题目数量
alltime:integer;//总时间
end;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
sublgr: TGroupBox;
sortgrp: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
playeredit: TEdit;
pidcomb: TComboBox;
checkbox1: TCheckBox;
Button1: TButton;
sublistbox: TListBox;
sortlistbox: TListBox;
Button2: TButton;
subtimeedit: TMaskEdit;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
procedure sortproce(userid:shortstring;ntimes:word;alltime:integer);
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
hour,min,procount,sortcount:word;
ayorn:char;
proplayer:array [1..1600] of Prorecord;
playersort:array [1..200] of Rplayersort;
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin //关闭程序
application.Terminate;
end;
//添加记录
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
i:=1;
if (strtoint(playeredit.Text)<1) or (strtoint(playeredit.Text)>200) then
begin
showmessage('选手编号在1~200,请正确输入!');
exit;
end;
if checkbox1.Checked=true then //判定选手回答是否正确
ayorn:='Y'
else
ayorn:='N';
hour:=strtoint(copy(subtimeedit.Text,0,2));//小时,提交时间
min:=strtoint(copy(subtimeedit.Text,4,2)); //分钟,提交时间
sublistbox.Items.Add(subtimeedit.Text+' '+playeredit.Text+' '
+' '+pidcomb.Text+' '+ayorn);
//在提交情况列表中显示选手提交的每条记录
if procount>0 then
for i:=1 to procount do
if proplayer[i].userid=playeredit.Text then //该选手已经回答过问题
if proplayer[i].pid=pidcomb.Text then //该选手第 n 此做该题目
begin
if checkbox1.Checked=false then //回答错误
begin
proplayer[i].yorn:=false;
proplayer[i].antimes:=proplayer[i].antimes+1;
proplayer[i].alltimes:=proplayer[i].alltimes+20;
exit;
end
else //回答正确
begin
if proplayer[i].yorn=true then //已经正确回答
begin
showmessage('该选手已经正确回答该问题!');
exit;
end
else //没有正确回答过
begin
proplayer[i].alltimes:=(hour-9)*60+min+proplayer[i].antimes*20;//计算回答正确的时间
sortproce(proplayer[i].userid,proplayer[i].antimes,proplayer[i].alltimes); //调用排序函数
proplayer[i].yorn:=true;
inc(proplayer[i].antimes);
exit;
end;
end; //回答正确end
end;
//该选手没有回答过问题,或者没有回答过该问题
if (i>=procount) then
begin
proplayer[i].userid:=playeredit.Text;
proplayer[i].pid:=pidcomb.text;
proplayer[i].yorn:=checkbox1.Checked;
proplayer[i].antimes:=1;
inc(procount); //存储记录增加一条
if proplayer[i].yorn=false then //回答错误
begin
proplayer[i].alltimes:=20
end
else
begin //回答正确
proplayer[i].alltimes:=(hour-9)*60+min;
sortproce(proplayer[i].userid,proplayer[i].antimes,proplayer[i].alltimes); //调用排序函数
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
procount:=0; //初始化记录个数
sortcount:=0;
for i:=1 to 1600 do //初始化排名记录数组
begin
proplayer[i].userid:='';
proplayer[i].antimes:=0;
proplayer[i].alltimes:=0;
end;
for i:=1 to 200 do //初始化存储记录数组
begin
// playersort[i].sort:=0;
playersort[i].userid:='';
playersort[i].pnum:=0;
playersort[i].alltime:=0;
end;
end;
//排序函数
procedure tform1.sortproce(userid:shortstring;ntimes:word;alltime:integer);
var
i,j:integer;
tempsort:Rplayersort;
begin
i:=1;
if sortcount>0 then
begin
for i:=1 to sortcount do
if playersort[i].userid=userid then //该选手回答正确过,修改
begin
inc(playersort[i].pnum);
playersort[i].alltime:=playersort[i].alltime+alltime;
break;
end;//for end
end;//if end
if i>sortcount then //该选手没有回答正确过,添加
begin
playersort[i].userid:=userid;
playersort[i].pnum:=ntimes;
playersort[i].alltime:=alltime;
inc(sortcount); //排序记录增加一条
end;
for i:=1 to (sortcount-1) do //对记录排序
for j:=i+1 to sortcount do
begin
if playersort[i].pnum<playersort[j].pnum then //按题目数量 high to low
begin
tempsort.userid:=playersort[i].userid;
tempsort.pnum:=playersort[i].pnum;
tempsort.alltime:=playersort[i].alltime;
playersort[i].userid:=playersort[j].userid;
playersort[i].pnum:=playersort[j].pnum;
playersort[i].alltime:=playersort[j].alltime;
playersort[j].userid:=tempsort.userid;
playersort[j].pnum:=tempsort.pnum;
playersort[j].alltime:=tempsort.alltime;
//tempsort:=playersort[i];
//playersort[i]:=playersort[j];
//playersort[j]:=playersort[i];
end
else if (playersort[i].pnum=playersort[j].pnum) and
(playersort[i].alltime>playersort[j].alltime) then //按总时间 low to high
begin
tempsort.userid:=playersort[i].userid;
tempsort.pnum:=playersort[i].pnum;
tempsort.alltime:=playersort[i].alltime;
playersort[i].userid:=playersort[j].userid;
playersort[i].pnum:=playersort[j].pnum;
playersort[i].alltime:=playersort[j].alltime;
playersort[j].userid:=tempsort.userid;
playersort[j].pnum:=tempsort.pnum;
playersort[j].alltime:=tempsort.alltime;
//tempsort:=playersort[i];
//playersort[i]:=playersort[j];
//playersort[j]:=playersort[i];
end;
end;//for end
sortlistbox.Clear;
for i:=1 to sortcount do
sortlistbox.Items.Add(inttostr(i)+' '+playersort[i].userid+' '+
' '+inttostr(playersort[i].pnum)+' '
+inttostr(playersort[i].alltime));
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
form2.Show;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -