Files
python/TangDou/LuoGuBook/P1149.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

34 lines
842 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 10;
//数字0-9需要的火柴个数,这个字典妙啊~,成为解决火柴棍难题的关键~
int a[N] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
// 根据数字获取对应的火柴棍数量
int getNum(int n) {
if (n == 0) return a[0];
int s = 0;
while (n) {
int m = n % 10;
s += a[m];
n /= 10;
}
return s;
}
int n, cnt;
int main() {
//等号2个,加号2个
//给n根火柴棍,要求全部用上
//n的极限值是24,那么去掉4根就剩下20根,就是3个数加在一起需要20根
cin >> n;
for (int i = 0; i <= 999; i++)
for (int j = 0; j <= 999; j++)
if (getNum(i) + getNum(j) + getNum(i + j) == n - 4) cnt++;
cout << cnt << endl;
return 0;
}