GamerSK

Untitled

Jan 16th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.38 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5.  
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. /*
  12.  
  13. Uzivatel zada retazec, ktory pozostava zo znakov A a B
  14. //abb
  15. //aba
  16. //aaa
  17.  
  18. */
  19. //Vstup je veta, sifrovanie
  20. //Rozlozenie na slova a na znaky. Znaky do binarneho, oddelene #, prvy bit z kazdeho znaku inverzn�
  21. //Desifrovat, zobrazit.
  22. //---------------------------------------------------------------------------
  23. __fastcall TForm1::TForm1(TComponent* Owner)
  24.     : TForm(Owner)
  25. {
  26. }
  27. //---------------------------------------------------------------------------
  28. void TForm1::Kruh(int x, int y) {
  29.     Image1->Canvas->Brush->Color = clRed;
  30.     Image1->Canvas->Ellipse(x-10, y-10, x+10, y+10);
  31. }
  32. void __fastcall TForm1::Button1Click(TObject *Sender)
  33. {
  34.     Kruh(SpinEdit1->Value, SpinEdit2->Value);
  35. }
  36. //---------------------------------------------------------------------------
  37. //Dorobit funkciu
  38. void __fastcall TForm1::Button2Click(TObject *Sender)
  39. {
  40.     AnsiString s = "abaaabbabbbaaba",
  41.                str = "";
  42.     for (int i = 0; i < Memo1->Lines->Count; i++) {
  43.         int p = 0,
  44.         x = 1,
  45.         l = 0;
  46.         AnsiString h = Memo1->Lines->Strings[i];
  47.         for (int j = 1; j <= s.Length(); j++) {
  48.             if ( s[j] == h[x] ) {
  49.                 l++;
  50.             } else {
  51.                 l = 0;
  52.                 x = 1;
  53.             }
  54.             if ( l == h.Length() ) {
  55.                 p++;
  56.                 l = 0;
  57.                 x = 1;
  58.             }
  59.             if ( x == h.Length() ) {
  60.                 x = 1;
  61.             } else {
  62.                 x++;
  63.             }
  64.         }
  65.         str += h+" - "+IntToStr(p)+"x\n";
  66.     }
  67.     ShowMessage(str);
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TForm1::Button3Click(TObject *Sender)
  71. {
  72.     AnsiString str = Trim(Edit2->Text),
  73.                txt = "",
  74.                binary = "",
  75.                sifra = "";
  76.     for (int i = 1; i <= str.Length(); i++) {
  77.         if ( str[i] != ' ' && i < str.Length() ) {
  78.             txt += str[i];
  79.         } else {
  80.             txt += Trim(str[i]);
  81.             for (int j = 1; j <= txt.Length(); j++) {
  82.                 //8 bitov
  83.                 binary += decimalNumberToBinary(txt[j]);
  84.             }
  85.             txt = "";
  86.             sifra += binaryToDecimal(binary);
  87.             binary = "";
  88.         }
  89.     }
  90.     sifra[sifra.Length()] = ' ';
  91.     sifra = Trim(sifra);
  92.     ShowMessage(sifra);
  93. }
  94. //---------------------------------------------------------------------------
  95. AnsiString TForm1::binaryToDecimal(AnsiString binary) {
  96.     int s = 0,
  97.         n = 0;
  98.     for (int i = 1; i <= binary.Length(); i++) {
  99.         for (int j = 0; j < i; j++) {
  100.             n += 2*2;
  101.         }
  102.         if ( binary[i] == '1' ) {
  103.             s += n;
  104.         }
  105.     }
  106.     return char(s);
  107. }
  108. AnsiString TForm1::decimalNumberToBinary(char a) {
  109.     int c = a,
  110.         p = 0;
  111.     bool loop = true;
  112.     AnsiString b = "",
  113.                sifra = "";
  114.     while ( loop ) {
  115.         if ( c % 2 == 1 ) {
  116.             if ( p < 4 ) {
  117.                 b = "0" + b;
  118.             } else {
  119.                 b = "1" + b;
  120.             }
  121.         } else {
  122.             if ( p < 4 ) {
  123.                 b = "1" + b;
  124.             } else {
  125.                 b = "0" + b;
  126.             }
  127.         }
  128.         p++;
  129.         c /= 2;
  130.         if ( c == 0 ) {
  131.             for (int k = b.Length(); k < 8; k++) {
  132.                 b = "0" + b;
  133.             }
  134.             loop = false;
  135.             sifra += b + "#";
  136.         }
  137.     }
  138.     return sifra;
  139. }
  140.  
  141. float TForm1::diskriminant(int a, int b, int c) {
  142.     float d = b*b - 4*a*c;
  143.     return d;
  144. }
  145. void __fastcall TForm1::Button4Click(TObject *Sender)
  146. {
  147.     ShowMessage(FloatToStr(diskriminant(2, 1, 3)));
  148. }
  149. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment