- UID
- 38810
注册时间2007-12-2
阅读权限10
最后登录1970-1-1
周游历练
TA的每日心情 | 开心 2025-1-6 09:58 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
发表于 2007-12-30 10:16:24
|
显示全部楼层
6个人,报数4,从3开始,最终为1
15个人,报数5,从5开始,最终为5
10个人,报数5,从1开始,最终为3
测试通过,不知还有其他测试数据不?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Seach(n:integer;f:integer;s:integer):integer;
var
temp:array of Boolean;
i,j:Integer;
begin
setlength(temp,n+1);
for i:=0 to n do
temp:=True;
for i:=1 to n-1 do
begin
j:=0;
while j<f do
begin
if temp then j:=j+1;
if (s+1)<n+1 then
s:=s+1
else
s:=s+1-n;
end;
if (s-1)=0 then
temp[s-1+n]:=False
else
temp[s-1]:=False;
end;
for i:=1 to n do
if temp then Result:=i;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a:Integer;
begin
a:=Seach(StrToInt(Edit1.Text ),StrToInt(Edit2.Text ),StrToInt(Edit3.Text ) );
Edit4.Text :=IntToStr(a);
end;
end. |
|