#include <stdio.h>
static const char x36[36] = { '0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z', };
int main( int argc, char* argv[] ) { if (argc != 2) { printf ("Usage: %s number[0,46656)\n", argv[0]); return -1; } char n[4]; int i = atoi (argv[1]); if (i >= 46656 || i < 0) { printf ("Number overflow!\n"); return -2; } else if (i < 3600) { n[0] = x36[i / 100]; i %= 100; n[1] = x36[i / 10]; n[2] = x36[i % 10]; } else if (i < 12960) { i -= 3600; n[0] = x36[i / 260]; i %= 260; n[1] = x36[10 + i / 10]; n[2] = x36[i % 10]; } else { i -= 12960; n[0] = x36[i / 936]; i %= 936; n[1] = x36[i / 26]; n[2] = x36[10 + i % 26]; } n[3] = '\0'; printf ("%s = %s[x36]\n", argv[1], n); return 0; }
|