View Code of Problem 101

#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	string s1;
	while(getline(cin,s)){
		int t=0,j=0;
		for(int i=s.size()-1;i>=0;i--){
			if(t%3!=0&&s[i]!=','||t==0){
				s1[j]=s[i];
				j++;
			}
			if(t%3==0&&s[i]!=','&&t!=0){
				s1[j]=',';
				j++;
				s1[j]=s[i];
				j++;
			}
			if(s[i]!=',') t++;
		}
		for(int i=j-1;i>=0;i--) cout<<s1[i];
		cout<<endl; 
	}
}

Double click to view unformatted code.


Back to problem 101