Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "math.h"
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- const nero=100;
- const Nmax=10;
- const Mmax=10;
- typedef AnsiString mas2[Nmax][Mmax];
- int N=3, M=3;
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Edit1->Text=FloatToStr(N);
- Edit2->Text=FloatToStr(M);
- StringGrid1->ColCount=N+1;
- StringGrid1->RowCount=M+1;
- StringGrid1->Cells[0][0]="Main";
- for (int i=1; i<=N; i++)
- for (int p=1; p<=M; p++)
- {
- StringGrid1->Cells[0][i]="i="+IntToStr(i);
- StringGrid1->Cells[p][0]="p="+IntToStr(p);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- N=StrToInt(Edit1->Text);
- M=StrToInt(Edit2->Text);
- StringGrid1->ColCount=N+1;
- StringGrid1->RowCount=M+1;
- StringGrid1->Cells[0][0]="Main";
- for (int i=1; i<=N; i++)
- {
- for (int p=1; p<=M; p++)
- {
- StringGrid1->Cells[p][i]=IntToStr(random(100));
- StringGrid1->Cells[0][i]="i="+IntToStr(i);
- StringGrid1->Cells[p][0]="p="+IntToStr(p);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- mas2 a;
- for (int i=0; i<M; i++)
- for (int p=0; p<N; p++)
- a[i][p]=StringGrid1->Cells[p+1][i+1];
- int nm,i,j,k=0;
- nm= N*M;
- AnsiString b[nero];
- for(i=0;i<M;i++)
- {
- for(j=0;j<N;j++)
- {
- b[k++] = a[i][j];
- }
- }
- for(i=0;i < nm - 1; i++)
- for(j=i+1;j < nm; j++)
- if(b[i] == b[j])
- {
- for(k=j;k<nm-1;k++)
- b[k]=b[k+1];
- nm--;
- j--;
- }
- Memo1->Clear();
- Memo1->Lines->Add("количество различных элементов матрицы ="+IntToStr(nm));
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement