Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int search(char* Word, char* Word2)
- {
- int n = 0, g = 0, N = 0;
- for (int i = 0; ; i++)
- {
- if (Word2[i] != '\0')
- {
- n++;
- }
- else break;
- }
- for (int i = 0; ; i++)
- {
- if (Word[i] != '\0')
- {
- N++;
- }
- else break;
- }
- for (int i = 0; i < N + 1; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (Word[i] == Word2[j])
- {
- g++;
- Word[i] = '\0';
- }
- }
- }
- if (g >= n)
- {
- for (int i = 0; i < n; i++)
- {
- Word[i] = Word2[i];
- if (i == (n - 1))
- {
- Word[n] = '\0';
- return 1;
- }
- }
- }
- else
- {
- return 0;
- }
- }
- int main() {
- setlocale(0, "");
- int N(15);
- char* Word = new char[N];
- cout << "Введите первое слово: ";
- cin.getline(Word, N);
- char* Word2 = new char[N];
- cout << "Введите второе слово: ";
- cin.getline(Word2, N);
- switch (search(Word, Word2))
- {
- case 1:
- cout << Word << endl;
- cout << "Слово найдено!" << endl;
- break;
- default:
- cout << "Слово не найдено" << endl;
- break;
- }
- delete[] Word;
- delete[] Word2;
- system("pause");
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement