language: C++ 4.7.2 (gcc-4.7.2)
date: 928 days 21 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <climits>
#include <string>
#include <stdio.h>
 
typedef unsigned buf_t; 
 
static buf_t * reduce(unsigned val, buf_t * stp) {
   unsigned above = val / 10000; 
   if (above != 0) {
      stp = reduce(above, stp); 
      val -= above * 10000; 
   }
 
   buf_t digit  = val / 1000; 
   *stp++ = digit + '0'; 
   val -= digit * 1000; 
 
   digit  = val / 100; 
   *stp++ = digit + '0'; 
   val -= digit * 100; 
 
   digit  = val / 10; 
   *stp++ = digit + '0'; 
   val -= digit * 10; 
   *stp++ = val + '0'; 
   return stp; 
}
 
std::string itostr(int input) {
 
   buf_t buf[16]; 
 
   if(input == INT_MIN) 
      return std::string("-2147483648");  
 
   // handle negative
   unsigned val = input;
   if(input < 0) 
      val = -input;
 
   buf[0] = '0'; 
   buf_t* endp = reduce(val, buf+1); 
   *endp = 127; 
 
   buf_t * stp = buf+1; 
   while (*stp == '0') 
      stp++;
   if (stp == endp)
      stp--; 
 
   if (input < 0) { 
      stp--; 
      *stp = '-'; 
   }
   return std::string(stp, endp); 
}
 
std::string itostr(unsigned input) {
 
   buf_t buf[16]; 
 
   unsigned val = input;
   buf_t* endp = reduce(val, buf); 
   *endp = 127; 
 
   buf_t * stp = buf; 
   while (*stp == '0') 
      stp++;
   if (stp == endp)
      stp--; 
 
   return std::string(stp, endp); 
}
 
 
int main(void)
{
    int i = 0;
    i += itostr(INT_MIN).size();
    i += itostr(INT_MAX).size();
 
    i += itostr(unsigned(INT_MAX) + 1U).size();
    i += itostr(unsigned(~0)).size(); 
 
        char c = CHAR_MIN;
        do {
                i += itostr(c).size();
                i += itostr((11111111 * c)).size();
 
                if (c >= CHAR_MAX) break;
 
                c++;
        } while (1);
 
    while (i < 100000000)
        i += itostr(i).size();
 
    printf("%d\n", i);
 
    return i;
}