In C++
#include <string> #include <iostream> void alphabet_position(std::string s) { for (int i = 0; i < s.size(); i++) { int pos = (int)((char)s[i] - 'a'); pos = pos < 0 ? pos + ('a' - 'A') : pos; if (pos >= 0 && pos <= 'z' - 'a') { std::cout << pos+1 << " "; } } } int main (int argc, char *argv[]) { alphabet_position("<The quick brown fox jumps over the lazy dog!>"); //print 20 8 5 17 21 9 3 11 2 18 15 23 14 6 15 24 10 21 13 16 19 15 22 5 18 20 8 5 12 1 26 25 4 15 7 return 0; }
Edited: there was a bug :D
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In C++
Edited: there was a bug :D