valenki13

lesson_291123

Nov 29th, 2023
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int find_subarray(int size_arr,
  8.                   int* arr,
  9.                   int size_sarr,
  10.                   int* sarr) {
  11.     bool is_find;
  12.     for (int k = 0; k < size_arr-size_sarr+1; k++) {
  13.         if (arr[k] == sarr[0]) {
  14.             is_find = true;
  15.             for (int n = 1; n < size_sarr; n++) {
  16.                 if (arr[k + n] != sarr[n]) {
  17.                     is_find = false;
  18.  
  19.                     break;
  20.                 }
  21.             }
  22.             if (is_find) {
  23.                 return k;
  24.             }
  25.         }
  26.     }
  27.     return -1;
  28. }
  29.  
  30. void test_find_subarray() {
  31.     int arr[]{3, 1, 4, 7, 5, 4, 6, 7};
  32.     int sarr[]{ 6, 7};
  33.     cout << "Out: " << find_subarray(size(arr), arr,
  34.                                      size(sarr), sarr);
  35. }
  36.  
  37. void req_show_array(int sz, int* arr) {
  38.     if (sz > 0) {
  39.         cout << arr[0] << " ";
  40.         req_show_array(sz - 1, arr + 1);
  41.     }
  42. }
  43.  
  44. void test_show_arr() {
  45.     int arr[]{ 1,2,3,4,5 };
  46.     req_show_array(size(arr), arr);
  47. }
  48. void task_hello() {
  49.     //setlocale(LC_ALL, "ru");
  50.     std::string name;
  51.     cout << "Как твоё имя? ";
  52.     cin >> name; // смешивать руский ввод и вывод, так не получится
  53.     // ввести несколько слов - не получится
  54.     cout << "Hello " << name << endl;
  55. }
  56.  
  57. void str_input_output() {
  58.     char s1[] = "Hi";
  59.     const char* s2 = "Hello";
  60.     std::string s3 = "Salut";
  61.  
  62.     // Output c++
  63.     cout << s1 << endl;
  64.     cout << s2 << endl;
  65.     cout << s3 << endl;
  66.      
  67.     // Output puts
  68.     cout << "Puts" << endl;
  69.     puts(s1);
  70.     puts(s2);
  71.     puts(s3.data());
  72.    
  73.     // Input c++
  74.     //cin >> s1;
  75.     cout << s1 << " " << s1 << endl;
  76.     //cin >> s2; s2 - const
  77.     //cin >> s4;
  78.     //cout << s4<< " " << s4 << endl;
  79.     //cin >> s3;
  80.     cout << s3 << " " << s3 << endl;
  81.  
  82.     // Input fgets
  83.     char s4[128];
  84.     gets_s(s4); // позволяет записать в s4 - несколько слов
  85.     cout << s4;
  86.     //gets_s(s3.data());
  87.     //cout << s3;
  88.     cout << endl;
  89.  
  90.     // Charecter
  91.     char ch = getchar();
  92.     if (ch == 'y')
  93.         cout << ch << "YES" << endl;
  94.     // из библиотеки <conio.h> - без нажатия Enter
  95.     ch = _getch();
  96.     if (ch == 'n')
  97.         cout << ch << " " << "no" << endl;
  98. }
  99.  
  100. void str_input_output2() {
  101.     std::string s3 = "Salut";
  102.     //из файла <string>
  103.     std::getline(std::cin, s3);
  104.     cout << s3 << endl;
  105.  
  106.     // C - style input output
  107.     const char* s5 = "Hello";
  108.     printf("%s\n", s5);
  109.     printf("av: %d, std: %d \n", 14, 15);
  110.     printf("av: %2.2f, std: %2.2f \n", 14.213, 15.1223);
  111.  
  112.     char str[20];
  113.     scanf_s("%s", str, (unsigned int)sizeof(str));
  114.     printf("You str is: %s", str);
  115. }
  116.  
  117. int main() {
  118.     //test_find_subarray();
  119.     //test_show_arr();
  120.     str_input_output2();
  121.     //task_hello();
  122.     return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment