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 tmp_symbol = -1;
- UCHAR tmp_word = 0;
- UCHAR updating_tmp_word = 0;
- // Ввод последовательности
- do {
- tmp_symbol++;
- scanf_s("%c", &word_sequence[tmp_word][tmp_symbol]);
- if (word_sequence[tmp_word][tmp_symbol] == ' ')
- {
- word_sequence[tmp_word][tmp_symbol] = '\0';
- tmp_symbol = -1;
- tmp_word++;
- }
- if (word_sequence[tmp_word][tmp_symbol] == '.')
- word_sequence[tmp_word][tmp_symbol + 1] = '\0';
- } while (word_sequence[tmp_word][tmp_symbol] != '.');
- word_sequence[tmp_word][tmp_symbol] = '\0';
- // Убираем не палиндромы и слова неотличающиеся от последнего слова
- for (UCHAR i = 0; i <= tmp_word; i++)
- {
- if(!is_equal(word_sequence[i], word_sequence[tmp_word - 1]) || is_polyndrome(word_sequence[i]))
- {
- upd_word_sequence[updating_tmp_word][0] = '\0';
- strcpy_s(upd_word_sequence[updating_tmp_word], word_sequence[i]);
- upd_word_sequence[updating_tmp_word][strlen(upd_word_sequence[updating_tmp_word])] = '\0';
- updating_tmp_word++;
- }
- }
- // Вывод преобразованной последовательности
- printf_s("\n");
- for (UCHAR i = 0; i < updating_tmp_word; i++)
- printf_s("%s ", upd_word_sequence[i]);
- printf_s("%s.", upd_word_sequence[updating_tmp_word]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement