Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- using namespace std;
- int find_subarray(int size_arr,
- int* arr,
- int size_sarr,
- int* sarr) {
- bool is_find;
- for (int k = 0; k < size_arr-size_sarr+1; k++) {
- if (arr[k] == sarr[0]) {
- is_find = true;
- for (int n = 1; n < size_sarr; n++) {
- if (arr[k + n] != sarr[n]) {
- is_find = false;
- break;
- }
- }
- if (is_find) {
- return k;
- }
- }
- }
- return -1;
- }
- void test_find_subarray() {
- int arr[]{3, 1, 4, 7, 5, 4, 6, 7};
- int sarr[]{ 6, 7};
- cout << "Out: " << find_subarray(size(arr), arr,
- size(sarr), sarr);
- }
- void req_show_array(int sz, int* arr) {
- if (sz > 0) {
- cout << arr[0] << " ";
- req_show_array(sz - 1, arr + 1);
- }
- }
- void test_show_arr() {
- int arr[]{ 1,2,3,4,5 };
- req_show_array(size(arr), arr);
- }
- void task_hello() {
- //setlocale(LC_ALL, "ru");
- std::string name;
- cout << "Как твоё имя? ";
- cin >> name; // смешивать руский ввод и вывод, так не получится
- // ввести несколько слов - не получится
- cout << "Hello " << name << endl;
- }
- void str_input_output() {
- char s1[] = "Hi";
- const char* s2 = "Hello";
- std::string s3 = "Salut";
- // Output c++
- cout << s1 << endl;
- cout << s2 << endl;
- cout << s3 << endl;
- // Output puts
- cout << "Puts" << endl;
- puts(s1);
- puts(s2);
- puts(s3.data());
- // Input c++
- //cin >> s1;
- cout << s1 << " " << s1 << endl;
- //cin >> s2; s2 - const
- //cin >> s4;
- //cout << s4<< " " << s4 << endl;
- //cin >> s3;
- cout << s3 << " " << s3 << endl;
- // Input fgets
- char s4[128];
- gets_s(s4); // позволяет записать в s4 - несколько слов
- cout << s4;
- //gets_s(s3.data());
- //cout << s3;
- cout << endl;
- // Charecter
- char ch = getchar();
- if (ch == 'y')
- cout << ch << "YES" << endl;
- // из библиотеки <conio.h> - без нажатия Enter
- ch = _getch();
- if (ch == 'n')
- cout << ch << " " << "no" << endl;
- }
- void str_input_output2() {
- std::string s3 = "Salut";
- //из файла <string>
- std::getline(std::cin, s3);
- cout << s3 << endl;
- // C - style input output
- const char* s5 = "Hello";
- printf("%s\n", s5);
- printf("av: %d, std: %d \n", 14, 15);
- printf("av: %2.2f, std: %2.2f \n", 14.213, 15.1223);
- char str[20];
- scanf_s("%s", str, (unsigned int)sizeof(str));
- printf("You str is: %s", str);
- }
- int main() {
- //test_find_subarray();
- //test_show_arr();
- str_input_output2();
- //task_hello();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment