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 = "AZ"; std::cout << s << ':' << C(s) << std::endl;
  27. s = "BA"; std::cout << s << ':' << C(s) << std::endl;
  28. s = "ZZ"; std::cout << s << ':' << C(s) << std::endl;
  29. s = "AAA"; std::cout << s << ':' << C(s) << std::endl;
  30. return 0;
  31. }
  32. /* end */
  33.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
A:1
Z:26
AA:27
AZ:52
BA:53
ZZ:702
AAA:703