fork download
  1. #include <string>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. const char digs[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  9.  
  10. unsigned long long code62(const string& ss)
  11. {
  12. unsigned long long code = 0;
  13. for(const char * s = ss.c_str(); *s; ++s)
  14. {
  15. code = code * 62 + (strchr(digs,*s)-digs); // Номер символа
  16. }
  17. return code;
  18. }
  19.  
  20. string decode62(unsigned long long val)
  21. {
  22. string res;
  23. while(val)
  24. {
  25. res = digs[val%62] + res;
  26. val /= 62;
  27. }
  28. return res;
  29. }
  30.  
  31.  
  32. int main(int argc, const char * argv[])
  33. {
  34. unsigned long long code = code62("BOOzE");
  35. cout << code << endl;
  36. cout << decode62(code) << endl;
  37. }
  38.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
558835242
BOOzE