fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdint>
  4. #include <limits>
  5.  
  6. std::string Radix62c(std::uint64_t N, std::string buff) {
  7. std::string const Char = "0123456789abcdefghijklnmopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ";
  8. int const Radix = 62;
  9. return (N == 0) ? buff
  10. : Radix62c(N / Radix, Char[N % Radix] + buff);
  11. }
  12.  
  13. std::string Radix62b(std::uint64_t N) {
  14. std::string const Char = "0123456789abcdefghijklnmopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ";
  15. int const Radix = 62;
  16. return (N == 0) ? ""
  17. : Radix62b(N / Radix) + Char[N % Radix];
  18. }
  19.  
  20. std::string Radix62a(std::uint64_t N) {
  21. std::string const Char = "0123456789abcdefghijklnmopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ";
  22. std::string Ret;
  23.  
  24. int const Radix = 62;
  25. while (N != 0){
  26. int Ch = N % Radix;
  27. N /= Radix; /* changed */
  28. Ret = Char[Ch] + Ret;
  29. }
  30. return Ret;
  31. }
  32.  
  33. int main() {
  34. std::uint64_t N = std::numeric_limits<std::uint64_t>::max();
  35. std::cout << N << " == " << Radix62a(N) << std::endl;
  36. std::cout << N << " == " << Radix62b(N) << std::endl;
  37. std::cout << N << " == " << Radix62c(N, "") << std::endl;
  38. return 0;
  39. }
  40. /* end */
  41.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
18446744073709551615 == lYGhA16ahyf
18446744073709551615 == lYGhA16ahyf
18446744073709551615 == lYGhA16ahyf