![]() |
|
#6
|
||||
|
||||
![]() Цитата:
Код:
uses Math; procedure TFMain.BTInputClick(Sender: TObject); var M: array of array of integer; f, f1: TextFile; i, j, b, OldSum, AllSum: integer; s: string; begin if od1.Execute then begin Memo1.Clear; AssignFile(f, od1.filename); Reset(f); i:= 0; AllSum:= 0; OldSum:= 0; while not Eof(f) do begin ReadLn(f, s); SetLength(M, i+1); b:= Pos(',', s); if b > 0 then begin OldSum:= StrToInt(Copy(s, b+1, Length(s))); Delete(s, b, Length(s)); end; b:= 0; for j := 1 to Length(s)-1 do if (s[j] in ['0'..'9']) then begin SetLength(M[i], b+1); M[i, b]:= StrToInt(s[j]); Inc(b); end; Inc(AllSum, SumInt(m[i])); Inc(i); end;{while} if OldSum = AllSum then Memo1.Lines.Add('файл обработан') else begin Reset(f); AssignFile(f1,'tmp'); Rewrite(f1); while not Eof(f) do begin ReadLn(f, s); b:= Pos(',', s); if b > 0 then begin Delete(s, b, Length(s)); s:= s + ',' + IntToStr(AllSum); end; Writeln(f1, s); end;{while} CloseFile(f); CloseFile(f1); if DeleteFile(od1.filename) then RenameFile('tmp', od1.filename); Memo1.Lines.Add(('Сумма элементов матрицы=' + IntToStr(AllSum))); end; end; {od1.Execute} end; З.Ы. можно ещё второго валю завалить, извнт за тавтологию, в смысле убрать лишний цикл уаил, совместив операции чтения\записи в первом, но так осталось для наглядности Я не понял Вашего вопроса, но всё же Вам на него отвечу! Последний раз редактировалось Alegun, 28.04.2015 в 20:05. |