fork download
  1. #include <iostream>
  2. int order(std::string s) {
  3. int n, len;
  4. if (s.empty())
  5. return 0;
  6. n = order(s.substr(0, (len = s.length()) - 1)) * 26;
  7. n += (int)((char)s[len - 1] - 'A' + 1);
  8. return n;
  9. }
  10.  
  11. class C {
  12. int n;
  13. public:
  14. C(std::string s) : n(order(s)) {};
  15. friend std::ostream &operator<<(std::ostream &stream, C c) {
  16. stream << c.n;
  17. return stream;
  18. }
  19. };
  20.  
  21. int main() {
  22. std::string s;
  23. s = "A"; std::cout << s << ':' << C(s) << std::endl;
  24. s = "Z"; std::cout << s << ':' << C(s) << std::endl;
  25. s = "AA"; std::cout << s << ':' << C(s) << std::endl;
  26. s = "AB"; std::cout << s << ':' << C(s) << std::endl;
  27. s = "AZ"; std::cout << s << ':' << C(s) << std::endl;
  28. s = "BA"; std::cout << s << ':' << C(s) << std::endl;
  29. s = "ZZ"; std::cout << s << ':' << C(s) << std::endl;
  30. s = "AAA"; std::cout << s << ':' << C(s) << std::endl;
  31. s = "AAB"; std::cout << s << ':' << C(s) << std::endl;
  32. s = "IO"; std::cout << s << ':' << C(s) << std::endl;
  33. s = "LUA"; std::cout << s << ':' << C(s) << std::endl;
  34. return 0;
  35. }
  36. /* end */
  37.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
A:1
Z:26
AA:27
AB:28
AZ:52
BA:53
ZZ:702
AAA:703
AAB:704
IO:249
LUA:8659