fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #include<iostream>
  4. #define Dark ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  5. #define ll long long
  6. #define endl "\n"
  7. int dff(char a,char b){//short for dif between letters
  8. int k;
  9. k=abs(a-b);
  10. k=min(k,26-k); return k;
  11. }
  12.  
  13.  
  14. int main(){ Dark
  15. string s; cin>>s;s='a'+s;
  16. int n=s.size(),v=0,x=0,k=0,ans=0;
  17.  
  18. for(int i=1;i<n;i++){
  19.  
  20. ans+=dff(s[i-1],s[i]);
  21. } cout<<ans;
  22. }
Success #stdin #stdout 0s 5240KB
stdin
Standard input is empty
stdout
Standard output is empty