fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int f(const std::string &text)
  5. {
  6. if (text.size()>0 && std::isalpha(text[0]))
  7. return std::toupper(text[0])-'A';
  8. else return -1; // or throw an exception
  9. }
  10.  
  11. int main() {
  12. cout << "A->" << f("A")<<endl;
  13. cout << "B->" << f("B")<<endl;
  14. cout << "c->" << f("c")<<endl;
  15. cout << "1->" << f("1")<<endl;
  16. cout << "empty ->" << f("")<<endl;
  17.  
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 4176KB
stdin
Standard input is empty
stdout
A->0
B->1
c->2
1->-1
empty ->-1