View Code of Problem 101

#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[1000],s[1000];
    while(scanf("%s",str) != EOF)
    {
        int i,index = 0,k = 0;
        for(i = strlen(str) - 1;i >= 0;i--)
        {
            if(str[i] != ',')
            {
                index++;
                s[k++] = str[i];
                if(index == 3)
                {

                    s[k++] = ',';
                    index = 0;
                }
            }
        }
        s[k] = '\0';
        for(i = k - 1;i > -1;i--)
        {
            printf("%c",s[i]);
        }
        printf("\n");
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 101