WA了
查看原帖
WA了
1247118
__Coder_Z__楼主2024/11/2 16:47
#include <iostream>
#include <unordered_map>
using namespace std;


unordered_map<char, int> matchstickCount = {
    {'0', 6}, {'1', 2}, {'2', 5}, {'3', 5}, {'4', 4},
    {'5', 5}, {'6', 6}, {'7', 3}, {'8', 7}, {'9', 6}
};


int calculateMatchsticks(int num) {
    int count = 0;
    while (num > 0) {
        count += matchstickCount['0' + num % 10];
        num /= 10;
    }
    return count;
}

int main() {
    
    for (int a = 0; a <= 999; ++a) {
        for (int b = 0; b <= 999; ++b) {
            int c = a + b;
            if (c > 999) continue; 
            if (calculateMatchsticks(a) + calculateMatchsticks(b) == calculateMatchsticks(c)) {
                cout << a << " + " << b << " = " << c << endl;
            }
        }
    }
    return 0;
}

rt.

2024/11/2 16:47
加载中...