- 注册时间
- 2008-2-6
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 51573
- 在线时间
- 小时
|
发表于 2008-7-28 09:33:41
|
显示全部楼层
今天来学校
顺便写了PASCAL代码
挂服务器上的计划任务里了
处理结构化数据,还是PASCAL要比C简单
呵呵- program square;
-
- {\$APPTYPE CONSOLE}
-
- uses
- SysUtils;
-
- const
- Ten6 = 1000000;
- StatusFileName = 'Square.Status';
- LogFileName = 'Square.Log';
-
- type
- TStatus = record
- S: array[0..439] of byte; //448 Byte
- Sum: array[0..7] of integer; //32 Byte
- SumMax: integer; //4 byte;
- Delta: array[0..7] of integer; //32 Byte
- DeltaMax: integer; //4 byte
- end;
-
- var
- Status: TStatus;
- StatusFile: File of TStatus;
- LogFile: TextFile;
- SumOfDigit6: array[0..999999] of integer;
- ExeFilePath: string;
- Counter: Int64;
-
- procedure WriteLog(s: string);
- begin
- AssignFile(LogFile, ExeFilePath + LogFileName);
- if FileExists(ExeFilePath + LogFileName) then
- Append(LogFile)
- else
- Rewrite(LogFile);
- writeln(LogFile, s);
- Close(LogFile);
- end;
-
- procedure InitStatus;
- var
- i: integer;
- begin
- for I := 0 to 447 do
- Status.s[i] := 0;
- for i := 0 to 7 do
- begin
- status.sum[i] := 0;
- status.delta[i] := 0;
- end;
- Status.Delta[0] := 1;
- Status.SumMax := 0;
- Status.DeltaMax := 0;
- end;
-
- procedure ReadStatus;
- begin
- AssignFile(StatusFile, ExeFilePath + StatusFileName);
- if FileExists(ExeFilePath + StatusFileName) then
- begin
- Reset(StatusFile);
- Read(StatusFile, Status);
- Close(StatusFile);
- end
- else
- InitStatus;
- end;
-
- procedure WriteStatus;
- begin
- AssignFile(StatusFile, ExeFilePath + StatusFileName);
- if FileExists(ExeFilePath + StatusFileName) then
- Rewrite(StatusFile)
- else
- Reset(StatusFile);
- Write(StatusFile, Status);
- Close(StatusFile);
- end;
-
- procedure AddDelta;
- var
- i: integer;
- begin
- for I := 0 to Status.SumMax do
- begin
- Status.Sum[i] := Status.Sum[i] + Status.Delta[i];
- end;
-
- for I := 0 to Status.SumMax do
- if Status.Sum[i] >= TEN6 then
- if i <= 7 then
- begin
- Status.Sum[i] := Status.Sum[i] - TEN6;
- INC(Status.Sum[i+1]);
- end
- else
- begin
- WriteLog(DateTimeToStr(now) + ': SUM is TOO Big!!');
- exit;
- end;
- if Status.Sum[Status.SumMax+1] > 0 then
- INC(Status.SumMax);
- end;
-
- procedure IncDelta;
- var
- i: integer;
- begin
- Status.Delta[0] := Status.Delta[0] + 2;
- for I := 0 to Status.DeltaMax do
- if Status.Delta[i] >= TEN6 then
- begin
- if i < 7 then
- begin
- Status.Delta[i] := Status.Delta[i] - TEN6;
- INC(Status.Delta[i + 1]);
- end
- else
- begin
- WriteLog('Delta is TOO Big!');
- exit;
- end;
- end;
- end;
-
- procedure InitSumOfDigit6;
- var
- i5, i4, i3, i2, i1, i0, k: integer;
- begin
- k := 0;
- for I5 := 0 to 9 do
- for I4 := 0 to 9 do
- for I3 := 0 to 9 do
- for I2 := 0 to 9 do
- for I1 := 0 to 9 do
- for I0 := 0 to 9 do
- begin
- SumOfDigit6[k] := i5 + i4 + i3 + i2 + i1 + i0;
- INC(k);
- end;
- end;
-
- procedure ProgressSum;
- var
- i: integer;
- s: integer;
- Str: String;
- begin
- s := 0;
- for I := 0 to Status.SumMax do
- s := s + SumOfDigit6[Status.Sum[i]];
- if (Status.S[s] = 0) then
- begin
- Status.S[s] := 1;
- for I := Status.SumMax downto 0 do
- Str := str + Format('%06d', [Status.Sum[i]]);
- writeln(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
- writelog(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
- end;
- end;
- procedure TEST;
- begin
- AddDelta;
- ProgressSum;
- IncDelta;
- end;
-
- begin
- { TODO -oUser -cConsole Main : Insert code here }
- //
- WriteLog('程序启动: ' + DateTimeToStr(now));
- WriteLn('程序启动: ' + DateTimeToStr(now));
- ExeFilePath := ExtractFilePath(ParamStr(0));
- Counter := 0;
- InitSumOfDigit6;
- ReadStatus;
- WriteLog('完成初始化: ' + DateTimeToStr(now));
- WriteLn('完成初始化: ' + DateTimeToStr(now));
- repeat
- TEST;
- INC(Counter);
- if Counter >= 10000000000 then
- begin
- WriteStatus;
- Counter := 0;
- end;
- until FALSE;
- end.
复制代码 |
|