View Code of Problem 101

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


int main()
{
	char a[100];
	while (scanf("%s", a) != EOF) {
		int count = 0;
		char b[100];
		for (int i = strlen(a) - 1,j=0;i >= 0;i--) {
			if (a[i] == ',')
				continue;
			else {
				if (count == 3) {
					b[j++] = ',';
					b[j++] = a[i];
					count = 1;
				}
				else {
					b[j++] = a[i];
					count++;
				}
				if (i == 0)
					b[j] = '\0';
			}
		}
		for (int i = strlen(b) - 1;i >= 0;i--) {
			printf("%c", b[i]);
		}
		printf("\n");
		
	}
	

}

Double click to view unformatted code.


Back to problem 101