#include using namespace std; int calc(char *num) { int result = 0; for (int i = 0; num[i] != '\0'; i++) { if (num[i] >= '0' && num[i] <= '9') { result += num[i] - '0'; } else if (num[i] >= 'A' && num[i] <= 'F') { result += num[i] - 'A' + 10; } } return result; } int duodecimal(int i) { char ch[20] = {'\0'}; int result = 0; int count = 0, base = 12; for (; i != 0;) { int s = i % base; result += s; if (s >= 10) { ch[count] = 'A' + (s - 10); } else { ch[count] = '0' + s; } count++; i /= base; } // cout << ch << " - " << i << endl; return result; } int main() { char *charA = new char[12], *charB = new char[12]; memset(charA, 0, 12); memset(charB, 0, 12); int numA = 0, numB = 0, numC = 0; for (int i = 1000; i <= 9999; i++) { sprintf(charA, "%X", i); sprintf(charB, "%d", i); numA = calc(charA); numB = calc(charB); // cout << charA << " - " << numA << " - " << charB << " - " << numB << endl; memset(charA, 0, 12); memset(charB, 0, 12); if (numA != numB) { continue; } numC = duodecimal(i); if (numA != numC) { continue; } cout << i << endl; } free(charA); free(charB); }