Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- setlocale(LC_ALL, "Rus");
- printf("Введите строку\n");
- char sentance[100];
- gets_s(sentance, 100);
- char words[50][50];
- int XCounter = 0, YCounter = 0;
- for (int i = 0; i <= strlen(sentance); i++) {
- if (sentance[i] != '\0') {
- if (sentance[i] != ' ') {
- words[XCounter][YCounter] = sentance[i];
- YCounter++;
- }
- else {
- if (YCounter > 0) {
- words[XCounter][YCounter] = '\0';
- YCounter = 0;
- XCounter++;
- }
- }
- }
- else {
- if (YCounter > 0) {
- words[XCounter][YCounter] = '\0';
- }
- else
- XCounter--;
- }
- }
- char flag = 1;
- for (int i = 0; i <= XCounter; i++) {
- int j = 0;
- flag = 1;
- while (flag && words[i][j] != '\0') {
- if (!(words[i][j] >= 65 && words[i][j] <= 90) && !(words[i][j] >= 97 && words[i][j] <= 122))
- flag = 0;
- j++;
- }
- if (!flag) {
- printf("%s - недопустимая комбинация символов\n", words[i]);
- for (int z = i; z < XCounter; z++)
- strcpy_s(words[z], words[z + 1]);
- XCounter--;
- i--;
- }
- }
- for (int i = 0; i < XCounter; i++) {
- if (strcmp(words[i], words[XCounter]) == 0) {
- for (int j = i; j < XCounter; j++)
- strcpy_s(words[j], words[j + 1]);
- XCounter--;
- i--;
- }
- }
- XCounter--;
- printf("\n");
- char vowelsSet[] = "aueoyi";
- char firstResultStr[100] = "", SecondResultStr[100] = "";
- printf("П.1. Напечатать все слова, отличные от последнего слова, если в слове подряд встречаются две гласные буквы\n");
- for (int i = 0; i <= XCounter; i++) {
- int y = 0;
- bool isFound = false;
- while ((y < strlen(words[i])) && !isFound) {
- for (int z = 0; z < 7; z++)
- if (words[i][y] == vowelsSet[z]) {
- int it = 0;
- bool vowelsFlag = false;
- while (it < 7 && !vowelsFlag) {
- if (words[i][y + 1] == vowelsSet[z]) {
- strcat_s(firstResultStr, words[i]);
- strcat_s(firstResultStr, " ");
- vowelsFlag = true;
- isFound = true;
- }
- it++;
- }
- }
- y++;
- }
- }
- if (strlen(firstResultStr) == 0)
- puts("Строка пустая");
- else
- puts(firstResultStr);
- printf("П.2. Напечатать все слова, отличные от последнего слова, если слово четной длины то добавить букву в середину\n");
- for (int i = 0; i <= XCounter; i++) {
- if (strlen(words[i]) % 2 == 0) {
- char temp[50];
- strcpy_s(temp, words[i]);
- strcpy_s(words[i], "");
- int tmp = 0;
- for (int a = 0; a < strlen(temp); a++) {
- if (tmp == strlen(temp) / 2) {
- words[i][tmp] = 'a';
- tmp++;
- }
- words[i][tmp] = temp[a];
- tmp++;
- }
- words[i][tmp] = '\0';
- }
- strcat_s(SecondResultStr, words[i]);
- strcat_s(SecondResultStr, " ");
- }
- if (SecondResultStr[0] == 0)
- puts("Строка пустая");
- else
- puts(SecondResultStr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement