Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <stdlib.h>
- #include <vector.h>
- #pragma hdrstop
- #include "Unit6.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- vector<vector<int> > v;
- int *nn, *mm;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::SG1DrawCell(TObject *Sender, int ACol,
- int ARow, TRect &Rect, TGridDrawState State)
- {
- int x,y;
- y = Rect.Top + (Rect.Height() - SG1->Canvas->TextHeight(SG1->Cells[ACol][ARow])) / 2;
- x = Rect.Left + (Rect.Width() - SG1->Canvas->TextWidth(SG1->Cells[ACol][ARow])) / 2;
- if (!SG1->ColCount || !SG1->RowCount)
- if ((ARow == 0) || (ACol == 0)) {
- SG1->Canvas->Brush->Color = clBtnFace;
- SG1->Canvas->Font->Color = clBlack;
- SG1->Canvas->FillRect(Rect);
- SG1->Canvas->TextOut(x, y, SG1->Cells[ACol][ARow]);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- srand(time(0));
- int n = StrToInt(Edit1->Text), m = StrToInt(Edit2->Text);
- nn = &n;
- mm = &m;
- v.assign(n, vector<int>(m));
- SG1->ColCount = n + 1;
- SG1->RowCount = m + 1;
- for (int i = 1; i <= n; i++)
- SG1->Cells[i][0] = IntToStr(i);
- for (int i = 1; i <= m; i++)
- SG1->Cells[0][i] = IntToStr(i);
- for (int i = 1; i <= n; i++)
- for (int j = 1; j <=m; j++) {
- v[i][j] = rand() % 10;
- SG1->Cells[i][j] = IntToStr(v[i][j]);
- }
- Label1->Caption = "Íàæìèòå ''Íàéòè'' äëÿ ïîèñêà èñêîìûõ ýëåìåíòîâ";
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- int s = 0;
- for (int i = 1; i < *nn-1; i++)
- for (int j = 0; j < *mm; j++) {
- if ((v[i][j] > v[i-1][j-1]) && (v[i][j] < v[i+1][j+1])) s++;
- }
- Label1->Caption = "Íàéäåíî "+IntToStr(s)+" ýëåìåíòîâ, óäîâëåòâîðÿþùèõ óñëîâèþ";
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement