fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4.  
  5. int num4base(int base, char c) {
  6. if (c >= '0' && c <= '9')
  7. return c - '0';
  8. if (c >= 'a' && c <= 'z')
  9. return c - 'a' + 10;
  10. if (c >= 'A' && c <= 'Z')
  11. return c - 'A' + 10;
  12. return -1;
  13. }
  14.  
  15. unsigned int interpret4base(int base, const std::string &value) {
  16. unsigned int r = 0;
  17. for (std::string::const_iterator p = value.begin(); p != value.end(); p++) {
  18. r *= base;
  19. r += num4base(base, *p);
  20. }
  21. return r;
  22. }
  23.  
  24. char digit2char(int v) {
  25. if (v >= 0 && v <= 9)
  26. return v + '0';
  27. if (v >= 10 && v <= 35)
  28. return v - 10 + 'a';
  29. return -1;
  30. }
  31.  
  32.  
  33. std::string change4base(int base, unsigned int n) {
  34. std::string ret;
  35. if (n == 0) return "";
  36. ret = change4base(base, n / base);
  37. ret += digit2char(n % base);
  38. return ret;
  39. }
  40.  
  41. int main() {
  42. std::string linebuff;
  43. while (std::getline(std::cin, linebuff)) {
  44. std::istringstream ss_line(linebuff);
  45. int b;
  46. std::string v;
  47. while (ss_line >> b >> v) {
  48. unsigned int n = interpret4base(b, v);
  49. /**/std::cout << "n = " << n << std::endl;
  50. for (int i = 2; i <= 36; i++) {
  51. std::cout << i << "#";
  52. std::cout << change4base(i, n) << std::endl;
  53. }
  54. }
  55. return 0;
  56. }
  57. }
  58. /* end */
  59.  
  60.  
Success #stdin #stdout 0s 4400KB
stdin
16 deadbabe
stdout
n = 3735927486
2#11011110101011011011101010111110
3#100122100210210001200
4#3132223123222332
5#30122344134421
6#1414413520330
7#161402600604
8#33653335276
9#10570723050
10#3735927486
11#1647919685
12#8831a30a6
13#476cc28a5
14#276253874
15#16ceb1726
16#deadbabe
17#91d36cc6
18#61f27270
19#437f24b8
20#2i79aie6
21#21bff6ii
22#1akk149g
23#125a42hj
24#jd49956
25#f7do8ob
26#c2b8boi
27#9h9ll1i
28#7l225hi
29#6842o9l
30#53m7kg6
31#46f9hir
32#3farelu
33#2tf7mor
34#2e7m366
35#214kbpb
36#1ps9w3i