View Code of Problem 101

#include <iostream>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		string res;
		int cn=0;
		for(int i=s.length()-1;i>=0;i--){
			if(s[i]>='0'&&s[i]<='9'){
				cn++;
				res+=s[i];
				if(cn==3&&i>0){
					res+=',';
					cn=0;
				}
			}
		}
		for(int i=res.length()-1;i>=0;i--)
			cout<<res[i];
		cout<<endl;
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 101