View Code of Problem 101

#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int main(){
	char a[100];
	while(gets(a)){
		
	int n=strlen(a);
	char b[100];
	int k=0;
	for(int i=0;i<n;i++){
		if(a[i]!=','){
			b[k++]=a[i];
		}
	}
	char c[100];
	int x=0;
	int cnt=0;
	for(int j=k-1;j>=0;){
		if(cnt==3){
			c[x++]=',';
			cnt=0;
		}else{
			c[x++]=b[j];
			cnt++;
			j--;
		}
	}
	//cout<<x<<endl;
	for(int j=x-1;j>=0;j--)
	cout<<c[j];
	cout<<endl;
	}
	return 0; 
}

Double click to view unformatted code.


Back to problem 101