Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- void removeUppercase(char *str) {
- char result[100];
- int j = 0;
- for (int i = 0; str[i] != '\0'; i++) {
- if (str[i] < 'A' || str[i] > 'Z') {
- result[j++] = str[i];
- }
- }
- result[j] = '\0';
- printf("Строка не палиндром.\n0%s\n", result);
- }
- bool checkForPalindrome(char *str, size_t size) {
- for (size_t i = 0; i < size / 2; i++) {
- if (str[i] != str[size - 1 - i]) {
- return false;
- }
- }
- return true;
- }
- int main() {
- char str[100];
- printf("Введите строку:\n");
- fgets(str, sizeof(str), stdin);
- size_t size = strlen(str);
- if (str[size - 1] == '\n') {
- str[size - 1] = '\0';
- size--;
- }
- if (checkForPalindrome(str, size)) {
- printf("Палиндром.\n");
- } else {
- removeUppercase(str);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement