Advertisement
dxvmxnd

kpo_1_16_10

Oct 16th, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6.  
  7. void removeUppercase(char *str) {
  8. char result[100];
  9. int j = 0;
  10.  
  11. for (int i = 0; str[i] != '\0'; i++) {
  12. if (str[i] < 'A' || str[i] > 'Z') {
  13. result[j++] = str[i];
  14. }
  15. }
  16. result[j] = '\0';
  17.  
  18. printf("Строка не палиндром.\n0%s\n", result);
  19. }
  20.  
  21. bool checkForPalindrome(char *str, size_t size) {
  22. for (size_t i = 0; i < size / 2; i++) {
  23. if (str[i] != str[size - 1 - i]) {
  24. return false;
  25. }
  26. }
  27. return true;
  28. }
  29.  
  30. int main() {
  31. char str[100];
  32.  
  33. printf("Введите строку:\n");
  34. fgets(str, sizeof(str), stdin);
  35.  
  36. size_t size = strlen(str);
  37. if (str[size - 1] == '\n') {
  38. str[size - 1] = '\0';
  39. size--;
  40. }
  41.  
  42. if (checkForPalindrome(str, size)) {
  43. printf("Палиндром.\n");
  44. } else {
  45. removeUppercase(str);
  46. }
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement