Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #pragma warning(disable : 4996)
- using namespace std;
- void getWord(char text[], char* wordList[], int &counter) {
- char* p;
- string cheto[777];
- p = strtok(text, " ,");
- while (p != NULL)
- {
- wordList[counter] = p;
- cheto[counter] = p;
- counter++;
- p = strtok(NULL, " ,");
- }
- }
- int main()
- {
- setlocale(LC_ALL, "ru");
- const int stringMaxAmount = 2;
- const int charAmount = 80;
- const int wordsAmount1 = 40;
- const int wordsAmount2 = 40;
- const int wordMaxLenght = 40;
- int stringAmount = stringMaxAmount;
- char text[stringMaxAmount][charAmount] = {
- "Ведьмаку заплатите чеканной монетой, чеканной монетой Уооу!",
- "Ведьмаку заплатите — зачтется все это вам.",
- };
- char* wordList1[wordsAmount1];
- char* wordList2[wordsAmount2];
- char* wordList3[wordsAmount2];
- int counter1 = 0;
- int counter2 = 0;
- int counter3 = 0;
- cout
- << endl
- << "Вывод текста:"
- << endl;
- for (int i = 0; i < stringAmount; i++)
- cout
- << text[i]
- << endl;
- //Забирает слова из предложений
- getWord(text[0], wordList1, counter1);
- getWord(text[1], wordList2, counter2);
- //Сортировка слов в алфавитном порядке
- for (int i = counter1 - 1; i > 0; i--) {
- for (int j = i-1; j >= 0; j--) {
- if (stricmp(wordList1[i], wordList1[j]) < 0) {
- char* tmp = wordList1[i];
- wordList1[i] = wordList1[j];
- wordList1[j] = tmp;
- }
- }
- }
- //Вывод слов
- cout
- << endl
- << "Слова, которые есть в обеих строках:"
- << endl;
- for (int i = 0; i < counter1; i++) {
- for (int j = 0; j < counter2; j++) {
- if (stricmp(wordList1[i], wordList2[j]) == 0) {
- cout
- << wordList1[i]
- << endl;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement