View Code of Problem 101

#include<stdio.h>
#include<string.h>
int main()
{ 
  char a[50],b[50]; 
  int i,j,k,len;
  while(gets(a)!=NULL){
  	j=0;
  	k=0;
  	i=strlen(a)-1;
  	while(i>=0)
	  {
  		if(a[i]!=','){
  			if(k==3){
  				b[j++]=',';
  				k=0;
			  }
				b[j++]=a[i--];
  			    k++;	
		}
		else i--;
  	  }
  	  
  	  for(i=j-1;i>=0;i--)
  	  	printf("%c",b[i]);
	  printf("\n");
  }
  return 0;
}

Double click to view unformatted code.


Back to problem 101