Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include "math.h"
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. //---------------------------------------------------------------------------
  12. __fastcall TForm1::TForm1(TComponent* Owner)
  13. : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17. const nero=100;
  18. const Nmax=10;
  19. const Mmax=10;
  20. typedef AnsiString mas2[Nmax][Mmax];
  21. int N=3, M=3;
  22. void __fastcall TForm1::FormCreate(TObject *Sender)
  23. {
  24. Edit1->Text=FloatToStr(N);
  25. Edit2->Text=FloatToStr(M);
  26. StringGrid1->ColCount=N+1;
  27. StringGrid1->RowCount=M+1;
  28. StringGrid1->Cells[0][0]="Main";
  29. for (int i=1; i<=N; i++)
  30. for (int p=1; p<=M; p++)
  31. {
  32. StringGrid1->Cells[0][i]="i="+IntToStr(i);
  33. StringGrid1->Cells[p][0]="p="+IntToStr(p);
  34. }
  35. }
  36. //---------------------------------------------------------------------------
  37.  
  38. void __fastcall TForm1::Button1Click(TObject *Sender)
  39. {
  40. N=StrToInt(Edit1->Text);
  41. M=StrToInt(Edit2->Text);
  42. StringGrid1->ColCount=N+1;
  43. StringGrid1->RowCount=M+1;
  44. StringGrid1->Cells[0][0]="Main";
  45. for (int i=1; i<=N; i++)
  46. {
  47. for (int p=1; p<=M; p++)
  48. {
  49. StringGrid1->Cells[p][i]=IntToStr(random(100));
  50. StringGrid1->Cells[0][i]="i="+IntToStr(i);
  51. StringGrid1->Cells[p][0]="p="+IntToStr(p);
  52. }
  53. }
  54. }
  55. //---------------------------------------------------------------------------
  56.  
  57. void __fastcall TForm1::Button2Click(TObject *Sender)
  58. {
  59. mas2 a;
  60. for (int i=0; i<M; i++)
  61. for (int p=0; p<N; p++)
  62. a[i][p]=StringGrid1->Cells[p+1][i+1];
  63.  
  64. int nm,i,j,k=0;
  65. nm= N*M;
  66. AnsiString b[nero];
  67.  
  68. for(i=0;i<M;i++)
  69. {
  70. for(j=0;j<N;j++)
  71. {
  72. b[k++] = a[i][j];
  73. }
  74. }
  75.  
  76. for(i=0;i < nm - 1; i++)
  77. for(j=i+1;j < nm; j++)
  78. if(b[i] == b[j])
  79. {
  80. for(k=j;k<nm-1;k++)
  81. b[k]=b[k+1];
  82. nm--;
  83. j--;
  84. }
  85.  
  86. Memo1->Clear();
  87.  
  88. Memo1->Lines->Add("количество различных элементов матрицы ="+IntToStr(nm));
  89. }
  90. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement