Advertisement
BRIGADA_9301

Untitled

Nov 22nd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <string.h>
  4. #include <Windows.h>
  5.  
  6. UCHAR is_polyndrome(char *str)
  7. {
  8. for (char i = 0; i < strlen(str) / 2; i++)
  9. {
  10. if (str[i] != str[strlen(str) - i - 1])
  11. return 0;
  12. }
  13. return 1;
  14. }
  15.  
  16. char is_equal(char *str, char *last_str)
  17. {
  18. if (strlen(str) == strlen(last_str))
  19. {
  20. for (char i = 0; i < strlen(str); i++)
  21. if (str[i] != last_str[i])
  22. return 0;
  23. }
  24. else
  25. return 0;
  26.  
  27. return 1;
  28. }
  29.  
  30. const UCHAR N_MAX_SYMBOLS = 9;
  31. const UCHAR N_MAX_WORDS = 50;
  32.  
  33. int main()
  34. {
  35. char word_sequence[N_MAX_WORDS][N_MAX_SYMBOLS];
  36. char upd_word_sequence[N_MAX_WORDS][N_MAX_SYMBOLS];
  37. char lenth[N_MAX_WORDS];
  38. int tmp_symbol = -1;
  39. UCHAR tmp_word = 0;
  40. UCHAR updating_tmp_word = 0;
  41. // Ввод последовательности
  42. do {
  43. tmp_symbol++;
  44. scanf_s("%c", &word_sequence[tmp_word][tmp_symbol]);
  45. if (word_sequence[tmp_word][tmp_symbol] == ' ')
  46. {
  47. word_sequence[tmp_word][tmp_symbol] = '\0';
  48. tmp_symbol = -1;
  49. tmp_word++;
  50. }
  51. if (word_sequence[tmp_word][tmp_symbol] == '.')
  52. word_sequence[tmp_word][tmp_symbol + 1] = '\0';
  53. } while (word_sequence[tmp_word][tmp_symbol] != '.');
  54. word_sequence[tmp_word][tmp_symbol] = '\0';
  55. // Убираем не палиндромы и слова неотличающиеся от последнего слова
  56. for (UCHAR i = 0; i <= tmp_word; i++)
  57. {
  58. if(!is_equal(word_sequence[i], word_sequence[tmp_word - 1]) || is_polyndrome(word_sequence[i]))
  59. {
  60. upd_word_sequence[updating_tmp_word][0] = '\0';
  61. strcpy_s(upd_word_sequence[updating_tmp_word], word_sequence[i]);
  62. upd_word_sequence[updating_tmp_word][strlen(upd_word_sequence[updating_tmp_word])] = '\0';
  63. updating_tmp_word++;
  64. }
  65. }
  66. // Вывод преобразованной последовательности
  67. printf_s("\n");
  68. for (UCHAR i = 0; i < updating_tmp_word; i++)
  69. printf_s("%s ", upd_word_sequence[i]);
  70. printf_s("%s.", upd_word_sequence[updating_tmp_word]);
  71.  
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement