[蓝桥杯][算法提高VIP]计算器

2021-09-07  本文已影响0人  863cda997e42

题目链接

//
//  main.c
//
//  Created by chen.cy on 2021/9/7.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    unsigned char status[] = {0x77, 0x12, 0x5d, 0x5b, 0x3a,
        0x6b, 0x6f, 0x52, 0x7f, 0x7b};
    unsigned char temp[] = {
        0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,
        1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
        1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
        2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
        1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
        2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
        2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
        3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
    };
    int n, i, sum;
    unsigned char s1[100];
    unsigned char s2[100];
    
    scanf("%d", &n);
    scanf("%s %s", s1, s2);
    
    for (i = 0, sum = 0; i < n; i++) {
        sum += temp[status[s1[i] - '0'] ^ status[s2[i] - '0']];
    }
    printf("%d\n", sum);
    return 0;
}

上一篇 下一篇

猜你喜欢

热点阅读