#include <stdio.h>
#include <string.>
#include <ctype.>
void reversWord(char* start, char* end){
    while(start < end) {
        char temp = *start;
        *start = *end;
        *end = temp;
        start++;
        end--;
    }
}
int main(){
    char s[101];
    printf("Enter the encoded message: ");
    fgets(s, sizeof(s), stdin);
    s[strcspn(s, "\n")] = 0;
    
    for(int i = 0; s[i] != '\0'; i++){
        if (!isalpha(s[i]) && s[i] != ' '){
            printf("Invalid input\n");
            return 0;
        }
    }
    char* word_start = s;
    char* current = s;
    
    while(*current != '\0'){
        if(*current == ' '){
            reverseWord(word_start, current - 1);
            word_start = current + 1;
        }
        current++;
    }
    reverseWord(word_start, current - 1);
    return 0;
}