fork(9) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <stdexcept>
  5.  
  6. class N62
  7. {
  8. public:
  9. explicit N62(const std::string& digits) : N62(digits.c_str(), digits.size()) {}
  10. N62(const char* digits, std::size_t len) : value(0u)
  11. {
  12. for (std::size_t i = 0; i != len; ++i) {
  13. auto pos = std::find(std::begin(base), std::end(base), digits[i]);
  14. if (pos == std::end(base)) {
  15. throw std::runtime_error("bad format");
  16. }
  17. value *= base_size;
  18. value += pos - std::begin(base);
  19. }
  20. }
  21. N62(std::size_t value) : value(value) {}
  22. operator std::size_t () const { return value; }
  23. std::string str() const
  24. {
  25. if (value == 0u) {
  26. return "0";
  27. }
  28. std::string res;
  29. for (std::size_t n = value; n != 0; n /= base_size) {
  30. res.push_back(base[n % base_size]);
  31. }
  32. std::reverse(res.begin(), res.end());
  33. return res;
  34. }
  35.  
  36. private:
  37. std::size_t value;
  38. private:
  39. static constexpr char base[] =
  40. "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  41. static constexpr std::size_t base_size = 62;
  42. };
  43.  
  44. std::ostream& operator << (std::ostream& os, const N62& n)
  45. {
  46. return os << n.str() << "(" << std::size_t(n) << ")";
  47. }
  48.  
  49. constexpr char N62::base[];
  50.  
  51. N62 operator "" _n62 (const char *t, std::size_t len)
  52. {
  53. return N62(t, len);
  54. }
  55.  
  56. int main()
  57. {
  58. N62 a = "42"_n62;
  59. N62 b = 42;
  60.  
  61. std::cout << a << "*" << b << " = " << N62(a * b) << std::endl;
  62.  
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
42(250)*G(42) = 2Jm(10500)