Advertisement
BRIGADA_9301

Untitled

Nov 22nd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 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 cnt_symbol = -1;
  39. UCHAR cnt_word = 0;
  40. UCHAR updating_cnt_word = 0;
  41.  
  42. // Ввод последовательности
  43. do
  44. {
  45. cnt_symbol++;
  46. scanf_s("%c", &word_sequence[cnt_word][cnt_symbol]);
  47.  
  48. if (word_sequence[cnt_word][cnt_symbol] == ' ')
  49. {
  50. word_sequence[cnt_word][cnt_symbol] = '\0';
  51. cnt_symbol = -1;
  52. cnt_word++;
  53. }
  54. if (word_sequence[cnt_word][cnt_symbol] == '.')
  55. word_sequence[cnt_word][cnt_symbol + 1] = '\0';
  56. } while (word_sequence[cnt_word][cnt_symbol] != '.');
  57. word_sequence[cnt_word][cnt_symbol] = '\0';
  58.  
  59. // Убираем не палиндромы и слова равные последнему слову
  60. for (UCHAR i = 0; i < cnt_word; i++)
  61. {
  62. if(!is_equal(word_sequence[i], word_sequence[cnt_word - 1]) && is_polyndrome(word_sequence[i]))
  63. {
  64. upd_word_sequence[updating_cnt_word][0] = '\0';
  65. strcpy_s(upd_word_sequence[updating_cnt_word], word_sequence[i]);
  66. upd_word_sequence[updating_cnt_word][strlen(upd_word_sequence[updating_cnt_word]) - 1] = '\0';
  67. updating_cnt_word++;
  68. }
  69. }
  70.  
  71. // Вывод преобразованной последовательности
  72. printf_s("\n");
  73. for (UCHAR i = 0; i < updating_cnt_word; i++)
  74. printf_s("%s ", upd_word_sequence[i]);
  75. printf_s("%s.", upd_word_sequence[updating_cnt_word]);
  76.  
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement