一道面试题

给一个文本文档其中有姓名,手机号码,固定电话,请按照手机号码排序。 我当时给出的算法如下: var ay,by : array[0..5] of string; f : TextFile; s : string; list : TStringList; value : string; i,j : integer; a,b : string; begin hash := THashedStringList.Create; mmo1.Clear; i := 0; j := 0; list := TStringList.Create; s:= 'C:\Users\Administrator\Desktop\123.txt'; AssignFile(f,s); Reset(f); while not eof(f) do begin readln(f,ay[i]); i := i+1; end; //a := StrPas(StrScan(PChar(ay[0]),',')); //ShowMessage(a); //b := StrPas(StrRScan(PChar(ay[0]),',')); //b:=MidStr(ay[0],4,11); //ShowMessage(b); for i:= 0 to 4 do begin j:= Pos(',',ay[i]); if j<>5 then by[i] := midstr(ay[i],j-2,11)+'='+ay[i] else by[i] := MidStr(ay[i],j-1,11)+'='+ay[i]; end; for i:= 0 to 4 do begin list.Add(By[i]); end; list.Sort; for i:=0 to 4 do begin mmo1.Lines.Add(list.ValueFromIndex[i]); end; CloseFile(f); //mmo1.Lines.SaveToFile('C:\Users\Administrator\Desktop\123.txt'); //mmo1.Lines.AddStrings(list); // end; end;

posted on 2012-07-12 21:39  凝望远  阅读(103)  评论(0编辑  收藏  举报

导航