View Code of Problem 101

#include<stdio.h>
#include<string.h>
#define N 1000

int main()
{
    int i,s,t,j,k;
    char arr1[N],arr2[N];
    while(gets(arr1))//scanf("%s",&arr1) != EOF
    {
        s = strlen(arr1);
        j=1;
        k=0;
        for(i = s-1; i >= 0; i --)
        {
            if(arr1[i] != ',')
            {
                arr2[k++] = arr1[i];
                if(j%3==0)
                    arr2[k++] = ',';
                j++;
            }

        }
        //printf("%d\n",j);
        t = strlen(arr2);
        //printf("%d\n",t);
        for(i = t-1; i >= 0; i--)
            printf("%c",arr2[i]);
        printf("\n");
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 101