View Code of Problem 101

#include<stdio.h>
#include<string.h>
int main()
{
	char str1[1000],str[1000],str2[1000];
	int i,k,d,l,len;
	while(gets(str1)!=EOF){
		d=0,k=0;
		len=strlen(str1);
		for(i=len-1;i>=0;i--)
			if(str1[i]!=','){
				if(d==3){
					str[k++]=',';
					d=1;
				}
				else 
					d++;
				str[k++]=str1[i];
			}
		k--;
		len=strlen(str);
		for(i=len-1;i>=0;i--){
			printf("%c",str[i]);
		}
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 101