1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int n,k=0,h; 6 char s1[1001],s2[1001]; 7 cin>>n>>s1>>s2; 8 for(;--n>=0;) 9 { 10 h=s1[n]-s2[n]; 11 if(h<0) h=-h; 12 if(h>5) h=10-h; 13 k+=h; 14 } 15 cout<<k; 16 }
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int n,k=0,h; 6 char s1[1001],s2[1001]; 7 cin>>n>>s1>>s2; 8 for(;--n>=0;) 9 { 10 h=s1[n]-s2[n]; 11 if(h<0) h=-h; 12 if(h>5) h=10-h; 13 k+=h; 14 } 15 cout<<k; 16 }