CPP
cpp
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
#include <iostream>
using namespace std;
unsigned char log10(unsigned char c) {
if (c >= 100) return 2;
else if (c >= 10) return 1;
else return 0;
}
string reprCharAsInt(unsigned char c) {
unsigned char l = log10(c) + 1;
char cArr[l];
for (unsigned char i = l; i > 0; i--) {
cArr[i - 1] = c%10 + 48;
c /= 10;
}
string s(cArr); //This line causes problems.
//s.resize(l); //This line would solve the problem,
//but I'm not sure if it's a good solution.
return s;
}
int main() {
for (unsigned short i = 0; i < 256; i++) {
cout << i << ": ";
cout << reprCharAsInt((unsigned char) i);
cout << endl;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run