A:简单题

每次判断向上转快,还是向下转快即可

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define N 10005
#define ll long long
char s1[N] , s2[N];

int main()
{
   // freopen("a.in" , "r" , stdin);
    int n;
    while(~scanf("%d" , &n))
    {
        scanf("%s%s" , s1 , s2);
        int ans=0;
        for(int i=0 ; i<n ; i++){
            int a=s1[i]-'0';
            int b=s2[i]-'0';
            if(a>b){
                int t=a;
                a=b;
                b=t;
            }
            ans += min(b-a , 10+a-b);
        }
        printf("%d\n" , ans);
    }
    return 0;
}
View Code

相关文章:

  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-10-19
猜你喜欢
  • 2021-07-01
  • 2022-01-01
  • 2021-12-29
  • 2022-02-09
  • 2021-05-30
  • 2021-06-05
  • 2021-08-12
相关资源
相似解决方案