'commit'
This commit is contained in:
34
TangDou/LuoGuBook/P1149.cpp
Normal file
34
TangDou/LuoGuBook/P1149.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user