View Code of Problem 101

#include <stdio.h>
#include <string.h>
int main()
{
	char s1[100], s2[100];
	int i, j, k;
	while (scanf("%s", s1) != EOF )
	{
		
			
		j = 0;
		k = 0;
		for (i = strlen(s1)-1; i >= 0; i--)
		{
			if (s1[i] >= '0' && s1[i] <= '9')
			{
				if (k == 3)
				{
					k = 0;
					s2[j++] = ',';
				}
				s2[j++] = s1[i];
				k++;
			}
			
			else
				continue;
		}
		for (i = j - 1; i >= 0; i--)
		{
			printf("%c", s2[i]);
			if (i == 0)
				printf("\n");
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 101