读书人

小弟我想写一个彩票的统计程序现在遇

发布时间: 2012-02-12 17:16:33 作者: rapoo

我想写一个彩票的统计程序,现在遇到一个读入文本中数据的问题
如果文本中有下列彩票数据:

2 5 6
3 7 8
1 2 7
。。。。。。我要把它们读到程序中静态的数组a[1000][3]中,具体的代码怎么写啊?请高手给个详细代码,应该不难吧

[解决办法]
答:

假设C:\YourText.txt内容如下:(注意:是以单个空格分隔)
2 5 6
3 7 8
1 2 7


const
FileName = 'c:\YourText.txt ';
var
F : TextFile;
S : string;
A : array [1..1000,1..3] of Byte;//用了一个Byte数组。
I, J : integer;
SL : TStringList;
begin
AssignFile(F, FileName);
Reset(F);
I := 1;
while not Eof(F) do
begin
ReadLn(F, S);
SL := TStringList.Create;
SL.DelimitedText := S; //如果不是以单个空格分隔,则需改此二句(用StringReplace函数)
SL.Delimiter := ' ';
for J := 1 to 3 do
A[I,J] := StrToInt(SL[J-1]);
SL.Free;
Inc(I);
end;
CloseFile(F);

for I := 1 to 3 do //用一个Memo输出数组内容看一下
Memo1.Lines.Add(format( '%d %d %d ',[A[I,1],A[I,2],A[I,3]]));
end;

读书人网 >.NET

热点推荐