fork download
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. string str;
  12. cin>>str;
  13.  
  14. int n=str.size();
  15. std::vector<char> table(26);
  16. table = {
  17. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
  18. };
  19.  
  20. int i=0;
  21. while(i<n) {
  22. char c=str[i];
  23. auto search = std::find(table.begin(), table.end(), c);
  24. if(search!=table.end()) {
  25. int dist = std::distance(table.begin(), search);
  26. cout<<dist;
  27. }
  28. i++;
  29. }
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 16064KB
stdin
abcDefgw
stdout
01245622