Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #pragma warning(disable : 4996)
  4. using namespace std;
  5.  
  6. void getWord(char text[], char* wordList[], int &counter) {
  7.     char* p;
  8.     string cheto[777];
  9.  
  10.     p = strtok(text, " ,");
  11.     while (p != NULL)
  12.     {  
  13.         wordList[counter] = p;
  14.         cheto[counter] = p;
  15.         counter++;
  16.         p = strtok(NULL, " ,");
  17.     }
  18. }
  19.  
  20. int main()
  21. {
  22.     setlocale(LC_ALL, "ru");
  23.     const int stringMaxAmount = 2;
  24.     const int charAmount = 80;
  25.     const int wordsAmount1 = 40;
  26.     const int wordsAmount2 = 40;
  27.     const int wordMaxLenght = 40;
  28.     int stringAmount = stringMaxAmount;
  29.  
  30.  
  31.     char text[stringMaxAmount][charAmount] = {
  32.         "Ведьмаку заплатите чеканной монетой, чеканной монетой Уооу!",
  33.         "Ведьмаку заплатите — зачтется все это вам.",  
  34.     };
  35.  
  36.     char* wordList1[wordsAmount1];
  37.     char* wordList2[wordsAmount2];
  38.     char* wordList3[wordsAmount2];
  39.     int counter1 = 0;
  40.     int counter2 = 0;
  41.     int counter3 = 0;
  42.  
  43.     cout
  44.         << endl
  45.         << "Вывод текста:"
  46.         << endl;
  47.     for (int i = 0; i < stringAmount; i++)
  48.         cout
  49.         << text[i]
  50.         << endl;
  51.  
  52.     //Забирает слова из предложений
  53.     getWord(text[0], wordList1, counter1);
  54.     getWord(text[1], wordList2, counter2);
  55.  
  56.     //Сортировка слов в алфавитном порядке
  57.     for (int i = counter1 - 1; i > 0; i--) {
  58.         for (int j = i-1; j >= 0; j--) {
  59.             if (stricmp(wordList1[i], wordList1[j]) < 0) {
  60.                 char* tmp = wordList1[i];
  61.                 wordList1[i] = wordList1[j];
  62.                 wordList1[j] = tmp;
  63.             }
  64.         }
  65.     }
  66.  
  67.     //Вывод слов
  68.     cout
  69.         << endl
  70.         << "Слова, которые есть в обеих строках:"
  71.         << endl;
  72.  
  73.     for (int i = 0; i < counter1; i++) {
  74.         for (int j = 0; j < counter2; j++) {
  75.             if (stricmp(wordList1[i], wordList2[j]) == 0) {
  76.                 cout
  77.                     << wordList1[i]
  78.                     << endl;
  79.                 break;
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement