Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include <conio.h>
- using namespace std;
- void main()
- {
- setlocale(LC_ALL, "Rus");
- int i = 0;
- int j = 0;
- int lenght_str;
- int lenght_Pstr;
- int x = 0;
- char str[255] = { "\0" };
- char Pstr[255] = { "\0" };
- printf("Введите вашу строку: \t");
- scanf_s("%s", str, 255);
- printf("Ваша строка: %s\n", str);
- printf("Введите вашу подстроку: \t");
- scanf_s("%s", Pstr, 255);
- printf("Ваша подстрока: %s\n", Pstr);
- lenght_str = strlen(str);
- lenght_Pstr = strlen(Pstr);
- bool finded = false;
- int resultCount = 0;
- for (i = 0; i <= (lenght_str - lenght_Pstr); i++)
- {
- if (str[i] == Pstr[0])
- {
- finded = true;
- for (int j = 1; j < lenght_Pstr; j++)
- {
- char strChar = str[i + j];
- char pStrChar = Pstr[j];
- if ((strChar != pStrChar) || ((i + j) > lenght_str))
- {
- finded = false;
- break;
- }
- }
- if (finded == true)
- {
- resultCount++;
- }
- }
- }
- printf("Число входов = %d\n\n", resultCount);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement