17.11.2010, 14:38 | #1 (permalink) |
Новичок
Регистрация: 17.11.2010
Сообщений: 5
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 10
|
Сортировка массива
Необходимо отсортировать двумерный массив по возрастанию строк и столбцов (в массиве 0 и 1) но при этом если мы меняем местами то нам нужно знать что на 1 месте теперь стоит 3 строка или на 5 месте теперь стоит 8 столбец (то есть индексировать) и затем удалить 0 и 1-ные столбцы) ну а позде нужно будет провести некоторые вычесление ) там я думаю уже справлюсь... помогите кому не сложно |
17.11.2010, 14:38 | |
Helpmaster
Member
Регистрация: 08.03.2016
Сообщений: 0
|
Я думаю, что решение проблемы можно поискать в аналогичных топиках Сортировка по алфавиту Сортировка по алфавиту(помогите) Сортировка в Паскале |
17.11.2010, 20:27 | #3 (permalink) |
Новичок
Регистрация: 17.11.2010
Сообщений: 5
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 10
|
по сумме сначала строк а потом столбцов, и данные берутся из файла,
но при перемещении столбцов мы должны знать что например на 1 месте у нас теперь стоит 5 столбец |
17.11.2010, 20:34 | #4 (permalink) |
Специалист
Регистрация: 27.08.2008
Адрес: Санкт-Петербург
Сообщений: 27,807
Сказал(а) спасибо: 340
Поблагодарили 583 раз(а) в 208 сообщениях
Репутация: 113184
|
Ну так создайте массивы номеров строк и номеров столбцов, потом крутите метод пузырька для строк и столбцов по суммам, причем синхронно передвигайте компоненты массивов номеров. Вот и будете знать.
|
18.11.2010, 02:34 | #5 (permalink) |
Новичок
Регистрация: 17.11.2010
Сообщений: 5
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 10
|
мы не знаем сколько у нас элементов будет в строках и столбцах и удалять вроде как проще в динамике поэтому и спрашиваю сам в ней не бум бум
|
Ads | |
Member
Регистрация: 31.10.2006
Сообщений: 40200
Записей в дневнике: 0
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 55070
|
23.11.2010, 14:27 | #7 (permalink) |
Новичок
Регистрация: 17.11.2010
Сообщений: 5
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 10
|
Вот получившаяся прога:
unit ResolveArrays; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type { TColTotals } TColTotals = class(TObject) private FColSum: integer; FJobID: integer; public constructor Create; //Сумма по столбцу property ColSum: integer read FColSum; property JobID: integer read FJobID write FJobID; end; { TColList } TColList = class(TList) private FRowSum: integer; FStudentID: integer; function Get(Index: Integer): integer; procedure Put(Index: Integer; const AValue: integer); public function Add(AValue: integer): Integer; property Items[Index: Integer]: integer read Get write Put; default; property RowSum: integer read FRowSum; property StudentID: integer read FStudentID write FStudentID; end; { TResolveArray } TResolveArray = class(TObject) private //Список указателей на строки таблицы результатов FRows: TList; //Список итогов по столбцам FColTotals: TList; //Количество заданий FColCount: integer; //Получить значение ячейки таблицы результатов function GetCell(IndexRow, IndexCol: integer): integer; function GetColSum(const Index: integer): integer; //Получить номер задания по номеру столбца function GetJobID(IndexCol: integer): integer; //Получить количество строк в таблице ответов function GetRowCount: integer; function GetRowSum(const Index: integer): integer; //Получить номер участника по номеру строки function GetStudentID(IndexRow: integer): integer; //Установить оценку за задание в ячейку таблицы ответов procedure SetCell(IndexRow, IndexCol: integer; const AValue: integer); //Установить номер задания для стоблца procedure SetJobID(IndexCol: integer; const AValue: integer); //Установить номер учащегося по строке procedure SetStudentID(IndexRow: integer; const AValue: integer); //Удалить строку ответов procedure RowDelete(const Index: integer); //Удалить колонку procedure ColDelete(const Index: integer); //Дополнить количество строк до заданного размера procedure AppendRowTo(const ARowCount: integer); //Дополнить количество стобцов до указанного procedure AppendColTo(const AColCount: integer); public constructor Create; destructor Destroy;virtual; property Cell[IndexRow, IndexCol: integer]: integer read GetCell write SetCell; property StudentID[IndexRow: integer]: integer read GetStudentID write SetStudentID; property JobID[IndexCol: integer]:integer read GetJobID write SetJobID; property RowCount: integer read GetRowCount; property ColCount: integer read FColCount; property RowSum[const Index: integer]: integer read GetRowSum; property ColSum[const Index: integer]: integer read GetColSum; end; implementation { TResolveArray } function TResolveArray.GetCell(IndexRow, IndexCol: integer): integer; begin if (IndexCol<0) or (IndexCol>ColCount) or (IndexRow<0) or (IndexRow>RowCount) then Result := -1 else Result := Integer(TColList(FRows[IndexRow]).Items[IndexCol]); end; function TResolveArray.GetColSum(const Index: integer): integer; begin if (Index<0) or (Index>=ColCount) then Result := -1 else Result := TColTotals(FColTotals[Index]).ColSum; end; function TResolveArray.GetJobID(IndexCol: integer): integer; begin if (IndexCol<0) or (IndexCol>=ColCount) then Result := -1 else Result := TColTotals(FColTotals[IndexCol]).JobID; end; function TResolveArray.GetRowCount: integer; begin Result := FRows.Count; end; function TResolveArray.GetRowSum(const Index: integer): integer; begin if (Index<0) or (Index>=RowCount) then Result := -1 else Result := TColList(FRows[Index]).RowSum; end; function TResolveArray.GetStudentID(IndexRow: integer): integer; begin if (IndexRow<0) or (IndexRow>=RowCount) then Result := -1 else Result := TColList(FRows[IndexRow]).StudentID; end; procedure TResolveArray.SetCell(IndexRow, IndexCol: integer; const AValue: integer ); begin AppendRowTo(IndexRow+1); AppendColTo(IndexCol+1); with TColTotals(FColTotals[IndexCol]) do FColSum := FColSum - TColList(FRows[IndexRow]).Items[IndexCol]; TColList(FRows[IndexRow]).Items[IndexCol] := AValue; with TColTotals(FColTotals[IndexCol]) do FColSum := FColSum + TColList(FRows[IndexRow]).Items[IndexCol]; end; procedure TResolveArray.SetJobID(IndexCol: integer; const AValue: integer); begin AppendColTo(IndexCol+1); TColTotals(FColTotals[IndexCol]).JobID := AValue; end; procedure TResolveArray.SetStudentID(IndexRow: integer; const AValue: integer); begin AppendRowTo(IndexRow+1); TColList(FRows[IndexRow]).StudentID := AValue; end; procedure TResolveArray.RowDelete(const Index: integer); begin if (Index<0) and (Index >= RowCount) then Exit; TColList(FRows[Index]).Free; FRows.Delete(Index); end; procedure TResolveArray.ColDelete(const Index: integer); var I: integer; begin if (Index<0) or (Index >= ColCount) then Exit; for I:=0 to RowCount do TColList(FRows[I]).Delete(I); Dec(FColCount); TObject(FColTotals[Index]).Free; FColTotals.Delete(Index); end; procedure TResolveArray.AppendRowTo(const ARowCount: integer); var I, J: integer; NewIndex: integer; begin for I:=RowCount to ARowCount-1 do begin NewIndex := FRows.Add(TColList.Create); for J:=0 to ColCount-1 do TColList(FRows[NewIndex]).Add(0); end; end; procedure TResolveArray.AppendColTo(const AColCount: integer); var I, J: integer; begin if AColCount<ColCount then Exit; for I:=0 to RowCount-1 do for J:=ColCount to AColCount-1 do begin TColList(FRows[I]).Add(0); FColTotals.Add(TColTotals.Create); end; FColCount := AColCount; end; constructor TResolveArray.Create; begin inherited Create; FColCount:=0; FRows := TList.Create; FColTotals := TList.Create; end; destructor TResolveArray.Destroy; var I: integer; begin while RowCount>0 do RowDelete(0); FRows.Free; for I:=0 to FColTotals.Count-1 do TObject(FColTotals[I]).Free; FColTotals.Free; inherited Destroy; end; { TColList } function TColList.Get(Index: Integer): integer; begin Result := Integer(inherited Get(Index)); end; procedure TColList.Put(Index: Integer; const AValue: integer); begin if Index < Count then FRowSum := FRowSum - Get(Index); inherited Put(Index, TObject(AValue)); FRowSum := FRowSum + Get(Index); end; function TColList.Add(AValue: integer): Integer; begin Result := inherited Add(TObject(AValue)); end; { TColTotals } constructor TColTotals.Create; begin inherited Create; FColSum := 0; FJobID := -1; end; end. unit main; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, ResolveArrays; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; // procedure Button1Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { private declarations } FResolves: TResolveArray; public { public declarations } end; var Form1: TForm1; implementation { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin FResolves := TResolveArray.Create; end; procedure TForm1.FormDestroy(Sender: TObject); begin FResolves.Free; end; {procedure TForm1.Button1Click(Sender: TObject); var I, J: integer; S: string; begin FResolves.Cell[FResolves.RowCount, FResolves.ColCount] := 1; S := ''; for I:=0 to FResolves.RowCount-1 do begin for J:=0 to FResolves.ColCount-1 do S := S + ' ' + IntToStr(FResolves.Cell[I, J]); S := S + ' rs=' + IntToStr(FResolves.RowSum[I]) + sLineBreak; end; for J:=0 to FResolves.ColCount-1 do S := S + ' ' + IntToStr(FResolves.ColSum[J]); ShowMessage(S); end;} procedure TForm1.Button2Click(Sender: TObject); var fil:textfile; I,J:integer; A:string; begin FResolves.Cell[FResolves.RowCount, FResolves.ColCount] := 1; assignfile (Fil, 'Input.txt'); reset(fil); while not eof(fil) do while not eoln(fil) do for I:=0 to FResolves.RowCount-1 do begin for J:=0 to FResolves.ColCount-1 do Begin read(fil, A); ShowMessage(a); StrToInt(A); // FResolves.Cell[I, J]:=A; end; end; closefile(fil); end; procedure TForm1.Button1Click(Sender: TObject); begin end; initialization {$I main.lrs} end. Не могу корректно ввести из файла помогите плиз |
23.11.2010, 14:44 | #8 (permalink) |
Новичок
Регистрация: 17.11.2010
Сообщений: 5
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 10
|
Удалена ссылка на файлообменник. Модератор.
вот на файлообменнике проест |
Ads | |
Member
Регистрация: 31.10.2006
Сообщений: 40200
Записей в дневнике: 0
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 55070
|
Опции темы | |
Опции просмотра | |
|
|