Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <locale.h>
- #include <string.h>
- #include <Windows.h>
- UCHAR is_polyndrome(char *str)
- {
- for (char i = 0; i < strlen(str) / 2; i++)
- {
- if (str[i] != str[strlen(str) - i - 1])
- return 0;
- }
- return 1;
- }
- char is_equal(char *str, char *last_str)
- {
- if (strlen(str) == strlen(last_str))
- {
- for (char i = 0; i < strlen(str); i++)
- if (str[i] != last_str[i])
- return 0;
- }
- else
- return 0;
- return 1;
- }
- const UCHAR N_MAX_SYMBOLS = 9;
- const UCHAR N_MAX_WORDS = 50;
- int main()
- {
- char word_sequence[N_MAX_WORDS][N_MAX_SYMBOLS];
- char upd_word_sequence[N_MAX_WORDS][N_MAX_SYMBOLS];
- char lenth[N_MAX_WORDS];
- int cnt_symbol = -1;
- UCHAR cnt_word = 0;
- UCHAR updating_cnt_word = 0;
- // Ввод последовательности
- do
- {
- cnt_symbol++;
- scanf_s("%c", &word_sequence[cnt_word][cnt_symbol]);
- if (word_sequence[cnt_word][cnt_symbol] == ' ')
- {
- word_sequence[cnt_word][cnt_symbol] = '\0';
- cnt_symbol = -1;
- cnt_word++;
- }
- if (word_sequence[cnt_word][cnt_symbol] == '.')
- word_sequence[cnt_word][cnt_symbol + 1] = '\0';
- } while (word_sequence[cnt_word][cnt_symbol] != '.');
- word_sequence[cnt_word][cnt_symbol] = '\0';
- // Убираем не палиндромы и слова равные последнему слову
- for (UCHAR i = 0; i < cnt_word; i++)
- {
- if(!is_equal(word_sequence[i], word_sequence[cnt_word - 1]) && is_polyndrome(word_sequence[i]))
- {
- upd_word_sequence[updating_cnt_word][0] = '\0';
- strcpy_s(upd_word_sequence[updating_cnt_word], word_sequence[i]);
- upd_word_sequence[updating_cnt_word][strlen(upd_word_sequence[updating_cnt_word]) - 1] = '\0';
- updating_cnt_word++;
- }
- }
- // Вывод преобразованной последовательности
- printf_s("\n");
- for (UCHAR i = 0; i < updating_cnt_word; i++)
- printf_s("%s ", upd_word_sequence[i]);
- printf_s("%s.", upd_word_sequence[updating_cnt_word]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement