language: C++ 4.7.2 (gcc-4.7.2)
date: 629 days 23 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    #include <iostream>
    #include <string>
 
    std::string format(unsigned long long i) {
      char buffer[128]; // can be adapted more tightly with std::numeric_limits
 
      char* p = buffer + 128;
      *(--p) = '\0';
 
      unsigned char count = 0;
      while (i != 0) {
        *(--p) = '0' + (i % 10);
        i /= 10;
 
        if (++count == 3) { count = 0; *(--p) = ' '; }
      }
 
      return p;
    }
 
    int main() {
      std::cout << format(1234567890) << '\n';
    }