View Code of Problem 101

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

int main()
{
    int i,l,cnt;
    char str[100];
    char trs[100];int k;
    char ans[100];int d;
    while(scanf("%s",str)!=EOF){
        cnt=0;
        k=0;
        d=0;
        l=strlen(str);
        for(i=0;i<l;i++){
            if(str[i]!=','){
                trs[k++]=str[i];
            }
        }
        for(i=k-1;i>=0;){
            if(cnt==3){
                ans[d++]=',';
                cnt=0;
            }else{
                ans[d++]=trs[i];
                cnt++;
                i--;
            }
        }
        for(i=d-1;i>=0;i--){
            printf("%c",ans[i]);
            if(i==0){
                printf("\n");
            }
        }
    }
	return 0;
}

Double click to view unformatted code.


Back to problem 101