解题思路:

注意事项:

参考代码:

#include<iostream>

using namespace std;

int g[10][10], n, sum;

char a[110], b[110];

int main()

{

    cin >> n;

    for(int i = 0; i < n; i ++) cin >> a[i];

    for(int i = 0; i < n; i ++) cin >> b[i];

    

    g[0][1] = g[1][0] = 4;

    g[0][2] = g[2][0] = 3;

    g[0][3] = g[3][0] = 3;

    g[0][4] = g[4][0] = 4;

    g[0][5] = g[5][0] = 3;

    g[0][6] = g[6][0] = 2;

    g[0][7] = g[7][0] = 3;

    g[0][8] = g[8][0] = 1;

    g[0][9] = g[9][0] = 2;

    g[1][2] = g[2][1] = 5;

    g[1][3] = g[3][1] = 3;

    g[1][4] = g[4][1] = 2;

    g[1][5] = g[5][1] = 5;

    g[1][6] = g[6][1] = 6;

    g[1][7] = g[7][1] = 1;

    g[1][8] = g[8][1] = 5;

    g[1][9] = g[9][1] = 4;

    g[2][3] = g[3][2] = 2;

    g[2][4] = g[4][2] = 5;

    g[2][5] = g[5][2] = 4;

    g[2][6] = g[6][2] = 3;

    g[2][7] = g[7][2] = 4;

    g[2][8] = g[8][2] = 2;

    g[2][9] = g[9][2] = 3;

    g[3][4] = g[4][3] = 3;

    g[3][5] = g[5][3] = 2;

    g[3][6] = g[6][3] = 3;

    g[3][7] = g[7][3] = 2;

    g[3][8] = g[8][3] = 2;

    g[3][9] = g[9][3] = 1;

    g[4][5] = g[5][4] = 3;

    g[4][6] = g[6][4] = 4;

    g[4][7] = g[7][4] = 3;

    g[4][8] = g[8][4] = 3;

    g[4][9] = g[9][4] = 2;

    g[5][6] = g[6][5] = 1;

    g[5][7] = g[7][5] = 4;

    g[5][8] = g[8][5] = 2;

    g[5][9] = g[9][5] = 1;

    g[6][7] = g[7][6] = 5;

    g[6][8] = g[8][6] = 1;

    g[6][9] = g[9][6] = 2;

    g[7][8] = g[8][7] = 4;

    g[7][9] = g[9][7] = 3;

    g[8][9] = g[9][8] = 1;

    for(int i = 0; i < n; i ++) 

    {

        int x = a[i] - '0';

        int y = b[i] - '0';

        if( x != y) sum += g[x][y];

    }

    cout << sum;

    return 0;

}


点赞(0)
 

0.0分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论