View Code of Problem 101

#include <stdio.h>
#include <string.h> 
using namespace std;
int main(){
	
	char c[1000];
	char c1[1000];
	while( ~scanf("%s", &c)){
		int k=0;
		int cnt=0;
		for( int i=strlen(c)-1; i>=0; i-- ){
			if( c[i] != ','){
				c1[k] = c[i];
				k++;
				cnt ++;
				if( cnt == 3 ){
					c1[k] = ',';
					cnt = 0;
					k++;	
				}
				
			}
		}
		c1[k] = '\0';
		for( int i=k-1; i>=0; i-- ){
			printf("%c", c1[i]);
		}
		printf("\n");
	}

	return 0;
	
}

Double click to view unformatted code.


Back to problem 101