Advertisement
Amorf

Untitled

Sep 30th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.97 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. int main()
  5. {
  6.     setlocale(LC_ALL, "Rus");
  7.     printf("Введите строку\n");
  8.     char sentance[100];
  9.     gets_s(sentance, 100);
  10.     char words[50][50];
  11.  
  12.     int XCounter = 0, YCounter = 0;
  13.     for (int i = 0; i <= strlen(sentance); i++) {
  14.         if (sentance[i] != '\0') {
  15.             if (sentance[i] != ' ') {
  16.                 words[XCounter][YCounter] = sentance[i];
  17.                 YCounter++;
  18.             }
  19.             else {
  20.                 if (YCounter > 0) {
  21.                     words[XCounter][YCounter] = '\0';
  22.                     YCounter = 0;
  23.                     XCounter++;
  24.                 }
  25.             }
  26.         }
  27.         else {
  28.             if (YCounter > 0) {
  29.                 words[XCounter][YCounter] = '\0';
  30.             }
  31.             else
  32.                 XCounter--;
  33.         }
  34.     }
  35.     char flag = 1;
  36.     for (int i = 0; i <= XCounter; i++) {
  37.         int j = 0;
  38.         flag = 1;
  39.         while (flag && words[i][j] != '\0') {
  40.             if (!(words[i][j] >= 65 && words[i][j] <= 90) && !(words[i][j] >= 97 && words[i][j] <= 122))
  41.                 flag = 0;
  42.             j++;
  43.         }
  44.         if (!flag) {
  45.             printf("%s - недопустимая комбинация символов\n", words[i]);
  46.             for (int z = i; z < XCounter; z++)
  47.                 strcpy_s(words[z], words[z + 1]);
  48.             XCounter--;
  49.             i--;
  50.         }
  51.     }
  52.     for (int i = 0; i < XCounter; i++) {
  53.         if (strcmp(words[i], words[XCounter]) == 0) {
  54.             for (int j = i; j < XCounter; j++)
  55.                 strcpy_s(words[j], words[j + 1]);
  56.             XCounter--;
  57.             i--;
  58.         }
  59.     }
  60.     XCounter--;
  61.     printf("\n");
  62.     char vowelsSet[] = "aueoyi";
  63.     char firstResultStr[100] = "", SecondResultStr[100] = "";
  64.     printf("П.1. Напечатать все слова, отличные от последнего слова, если в слове подряд встречаются две гласные буквы\n");
  65.     for (int i = 0; i <= XCounter; i++) {
  66.         int y = 0;
  67.         bool isFound = false;
  68.         while ((y < strlen(words[i])) && !isFound) {
  69.             for (int z = 0; z < 7; z++)
  70.                 if (words[i][y] == vowelsSet[z]) {
  71.                     int it = 0;
  72.                     bool vowelsFlag = false;
  73.                     while (it < 7 && !vowelsFlag) {
  74.                         if (words[i][y + 1] == vowelsSet[z]) {
  75.                             strcat_s(firstResultStr, words[i]);
  76.                             strcat_s(firstResultStr, " ");
  77.                             vowelsFlag = true;
  78.                             isFound = true;
  79.                         }
  80.                         it++;
  81.                     }
  82.                 }
  83.             y++;
  84.         }
  85.     }
  86.     if (strlen(firstResultStr) == 0)
  87.         puts("Строка пустая");
  88.     else
  89.         puts(firstResultStr);
  90.     printf("П.2. Напечатать все слова, отличные от последнего слова, если слово четной длины то добавить букву в середину\n");
  91.     for (int i = 0; i <= XCounter; i++) {
  92.         if (strlen(words[i]) % 2 == 0) {
  93.             char temp[50];
  94.             strcpy_s(temp, words[i]);
  95.             strcpy_s(words[i], "");
  96.             int tmp = 0;
  97.             for (int a = 0; a < strlen(temp); a++) {
  98.                 if (tmp == strlen(temp) / 2) {
  99.                     words[i][tmp] = 'a';
  100.                     tmp++;
  101.                 }
  102.                 words[i][tmp] = temp[a];
  103.                 tmp++;
  104.             }
  105.             words[i][tmp] = '\0';
  106.  
  107.         }
  108.         strcat_s(SecondResultStr, words[i]);
  109.         strcat_s(SecondResultStr, " ");
  110.     }
  111.     if (SecondResultStr[0] == 0)
  112.         puts("Строка пустая");
  113.     else
  114.         puts(SecondResultStr);
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement