View Code of Problem 101

#include <bits/stdc++.h>
using namespace std;
#define N 100005

int main()
{
string str;
	char ch[N];
	int i,flag=0,n;
	while(cin>>str)
	{
		n=0,flag=0;
		int len=str.length();
		for(i=len-1;i>=0;i--){
			if(str[i]!=',') {
				ch[n++]=str[i];
				flag++;
				if(flag==3) {
					if(i>0) {
						ch[n++]=',';
					    flag=0;
					}					
				}
			}
		}
		for(i=n-1;i>=0;i--) {
			cout<<ch[i];
		}
		cout<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 101