View Code of Problem 101

#include<iostream>
using namespace std;
int main() {
	string s,s2;
	while(cin>>s) {
		s2="";
		for(int i=0; i<s.length(); i++) {
			if(s[i]!=',') s2+=s[i];
		}
		s=""; 
		for(int i=s2.length()-1; i>=0; i-=3) {
			if(i-3>=0) {
				for(int j=0; j<3; j++) s+=s2[i-j];
				s+=",";
			}else {
				for(int j=i; j>=0; j--) s+=s2[j];
			}
		}
		for(int i=s.length()-1; i>=0; i--) cout<<s[i];
		cout<<endl;
	}
}

Double click to view unformatted code.


Back to problem 101