View Code of Problem 101

#include <iostream>
#include <string.h>
#include <stack>
using namespace std;

int main(){
  char num[1000];
  int len,k;
  stack<char> s;
  while(scanf("%s",num)!=EOF){
    len = strlen(num);
    k=0;
    for(int j=len-1;j>=0;j--){
      if(num[j]!=','){
        s.push(num[j]);
        k++;
      }
      if(k%3==0&&j!=0)
        s.push(',');
    }
    
    while(!s.empty()){
      printf("%c",s.top());
      s.pop();
    }
    printf("\n");
  }
  return 0;
}

Double click to view unformatted code.


Back to problem 101