函式_1A2B3C

 avatar
user_3763047219
c_cpp
2 years ago
897 B
1
Indexable
Never
void _A_B_C(int num1, int num2);

#include <stdio.h>
void _A_B_C(int num1, int num2) {
    int n1[4] = {};
    int n2[4] = {};
    for (int i = 3; i >=0; i--) {
        n1[i] = num1 % 10;
        n2[i] = num2 % 10;
        num1 = num1 / 10;
        num2 = num2 / 10;
    }
    int A = 0;
    int B = 0;
    int C = 0;
    for (int i = 0; i < 4; i++) {
        int c_count = 0;
        for (int j = 0; j < 4; j++) {
            if (n1[i] == n2[j]&&i==j) {
                A++;
            }
            else if (n1[i] == n2[j] && i != j) {
                B++;
            }
            else {
                c_count++;
            }
        }
        if (c_count == 4) {
            C=C+2;
        }
    }
    printf("%dA%dB%dC", A, B,C);
}




int main() {
    int num1, num2;
    scanf("%d %d", &num1, &num2);
    _A_B_C(num1, num2);

    return 0;
}