View Code of Problem 114

#include <stdio.h>
void Reverse(char s[20])
{
    int len = strlen(s);
    char temp;
    for (int i = 0; i < len / 2; i++)
    {
        temp = s[i];
        s[i] = s[len - i - 1];
        s[len - i - 1] = temp;
    }
}
int main()
{
    char a[100];
    while (gets(a) != NULL)
    {
        char s[20];
        int j = 0;
        for (int i = 0; i < strlen(a); i++)
        {
            if (a[i] >= 'a' && a[i] <= 'z' || a[i] >= 'A' && a[i] <= 'Z')
            {
                s[j++] = a[i];
                if (i == strlen(a) - 1)
                {
                    s[j] = '\0';
                    Reverse(s);
                    printf("%s\n", s);
                    memset(s, 0, sizeof(s));
                    j = 0;
                }
                    
            }
            else
            {
                char c = a[i];
                s[j] = '\0';
                Reverse(s);
                printf("%s", s);
                printf("%c", c);
                memset(s, 0, sizeof(s));
                j = 0;
                if(i==strlen(a)-1)
                    printf("\n");
            }
        }
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 114