fork download
  1. // HenkanRadix.cpp : アプリケーションのエントリ ポイントを定義します。
  2. //
  3. #include <iostream>
  4. #include <string>
  5. #include <cstdint>
  6. #include <cctype>
  7. #include <algorithm>
  8. const std::string Base = "0123456789abcdefghijklnmopqrstuvwxyz";
  9.  
  10. char NumberToChar(const std::uint64_t& N) {
  11. return Base[N];
  12. }
  13.  
  14. std::size_t CharToNumber(const char& C) {
  15. return Base.find_first_of(std::tolower(C), 0);
  16. }
  17.  
  18. std::uint64_t StringToNumber(std::string Value,const std::uint64_t& Radix) {
  19. std::uint64_t Mul = 1;
  20. std::uint64_t T = 0;
  21. while (Value.size()){
  22. std::size_t N = CharToNumber(Value.back())*Mul;
  23. if (N == Base.npos) {
  24. Value.pop_back();
  25. continue;
  26. }
  27. T += N;
  28. Mul *= Radix;
  29. Value.pop_back();
  30. }
  31. return T;
  32. }
  33.  
  34. std::string NumberToString(std::uint64_t Value,const std::uint64_t& Radix) {
  35. std::string T;
  36. std::uint64_t Mod = 0;
  37. while (Value) {
  38. Mod = Value % Radix;
  39. Value /= Radix;
  40. T.push_back(NumberToChar(Mod));
  41. }
  42. std::reverse(T.begin(), T.end());
  43.  
  44. return T;
  45. }
  46.  
  47. bool MakeHoge(const std::string& Value,const std::uint64_t& Radix) {
  48. std::uint64_t N = StringToNumber(Value, Radix);
  49.  
  50. for (std::size_t i = 2; i <= 36; i++) {
  51. std::cout << i << ':' << NumberToString(N, i) << std::endl;
  52. }
  53.  
  54. return true;
  55. }
  56.  
  57.  
  58. int main()
  59. {
  60.  
  61. MakeHoge("deadbabe", 16);
  62.  
  63. return 0;
  64. }
  65.  
  66.  
Success #stdin #stdout 0s 4444KB
stdin
Standard input is empty
stdout
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:53n7kg6
31:46f9hir
32:3farelu
33:2tf7nor
34:2e7n366
35:214kbpb
36:1ps9w3i