Problem Link:http://codeforces.com/contest/731/problem/A
Code:
Code:
#include<bits/stdc++.h> using namespace std; #include<string.h> //#include<math.h> int main() { char ch[200]; int i,a,l,b,sum; while(cin>>ch) { l=strlen(ch); //a=ch[0]-96; sum=abs('a'-ch[0]); if(abs(26-sum)<sum) sum=26-sum; for(i=0;i<l-1;i++) { // cout<<ch[i]<<" "<<ch[i+1]<<endl; a=abs(ch[i]-ch[i+1]); b=abs(26-a); if(a>b) a=b; sum+=a; //cout<<"a="<<a<<endl; } cout<<sum<<endl; } return 0; }
No comments:
Post a Comment