Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. int getMin(int x,int y){
  6. if(x<y)return x;
  7. else return y;
  8. }
  9. int getMax(int x,int y){
  10. if(x<y)return y;
  11. else return x;
  12. }
  13.  
  14. int main()
  15. {
  16.  
  17. char CurrentChar ='a';
  18.  
  19. string s;
  20. cin>>s;
  21. int counter=0;
  22. for(int i=0;i<s.length();i++){
  23.  
  24. counter+=getMin((int)(abs(((int)s[i]-97)-((int)CurrentChar-97))),int(abs(26-getMax(((int)CurrentChar-97),((int)s[i]-97)))+getMin(((int)CurrentChar-97),((int)s[i]-97))));
  25. CurrentChar=s[i];
  26. cout<<counter<<endl;
  27. }
  28. cout<<counter;
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement