Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8. string s;
  9. cin>>s;
  10. int sum=0;
  11. int temp='a';
  12. for(int i=0;i<s.length();i++){
  13. if((int)s[i]> temp){
  14. sum+=min(abs(temp-s[i]),temp+26-s[i]);
  15. }else
  16. sum+=min(temp-s[i],s[i]+26-temp);
  17. temp=s[i];
  18. }
  19. cout<<sum<<endl;
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement