Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cmath>
- using namespace std;
- int getMin(int x,int y){
- if(x<y)return x;
- else return y;
- }
- int getMax(int x,int y){
- if(x<y)return y;
- else return x;
- }
- int main()
- {
- char CurrentChar ='a';
- string s;
- cin>>s;
- int counter=0;
- for(int i=0;i<s.length();i++){
- 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))));
- CurrentChar=s[i];
- cout<<counter<<endl;
- }
- cout<<counter;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement