Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.54 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #include <stdlib.h>
  5. #include <vector.h>
  6. #pragma hdrstop
  7.  
  8. #include "Unit6.h"
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. #pragma resource "*.dfm"
  12. TForm1 *Form1;
  13. vector<vector<int> > v;
  14. int n, m;
  15. //---------------------------------------------------------------------------
  16. __fastcall TForm1::TForm1(TComponent* Owner)
  17.         : TForm(Owner)
  18. {
  19. }
  20. //---------------------------------------------------------------------------
  21.  
  22. void __fastcall TForm1::SG1DrawCell(TObject *Sender, int ACol,
  23.       int ARow, TRect &Rect, TGridDrawState State)
  24. {
  25.         int x,y;
  26.         y = Rect.Top + (Rect.Height() - SG1->Canvas->TextHeight(SG1->Cells[ACol][ARow])) / 2;
  27.         x = Rect.Left + (Rect.Width() - SG1->Canvas->TextWidth(SG1->Cells[ACol][ARow])) / 2;
  28.         if ((ARow == 0) || (ACol == 0)) {
  29.                 SG1->Canvas->Brush->Color = clBtnFace;
  30.                 SG1->Canvas->Font->Color = clBlack;
  31.                 SG1->Canvas->FillRect(Rect);
  32.         }
  33.         SG1->Canvas->TextOut(x, y, SG1->Cells[ACol][ARow]);        
  34. }
  35. //---------------------------------------------------------------------------
  36.  
  37. void __fastcall TForm1::Button1Click(TObject *Sender)
  38. {
  39.         srand(time(0));
  40.         n = StrToInt(Edit1->Text);
  41.         m = StrToInt(Edit2->Text);
  42.         v.assign(m, vector<int>(n));
  43.         SG1->ColCount = n + 1;
  44.         SG1->RowCount = m + 1;
  45.         for (int i = 1; i <= n; i++)
  46.                 SG1->Cells[i][0] = IntToStr(i);
  47.         for (int i = 1; i <= m; i++)
  48.                 SG1->Cells[0][i] = IntToStr(i);
  49.         for (int i = 1; i <= n; i++)
  50.                 for (int j = 1; j <= m; j++) {
  51.                         v[i][j] = rand() % 10;
  52.                         SG1->Cells[i][j] = IntToStr(v[i][j]);
  53.                 }
  54.         Label1->Caption = "Íàæìèòå ''Íàéòè'' äëÿ ïîèñêà èñêîìûõ ýëåìåíòîâ";
  55. }
  56. //---------------------------------------------------------------------------
  57.  
  58. void __fastcall TForm1::Button2Click(TObject *Sender)
  59. {
  60.         int s = 0;
  61.         for (int i = 1; i < n-1; i++)
  62.                 for (int j = 0; j < m; j++) {
  63.                         if ((v[j][i] > v[j][i-1]) && (v[j][i] < v[j][i+1])) s++;
  64.         }
  65.         Label1->Caption = "Íàéäåíî "+IntToStr(s)+" ýëåìåíòîâ, óäîâëåòâîðÿþùèõ óñëîâèþ";
  66. }
  67. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement