Created
April 25, 2021 07:56
-
-
Save qichunren/0f8a943878b3285ab149c26bc2443b27 to your computer and use it in GitHub Desktop.
通过1,2,5,10组合出数字
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 通过1,2,5,10组合出数字 | |
static QList<quint8> get_number_combined_list(int number) | |
{ | |
QList<quint8> result; | |
if(number < 1) | |
{ | |
return result; | |
} | |
// 0 -> null | |
// 1 -> [1] | |
// 2 -> [2] | |
// 3 -> [1,2] | |
// 4 -> [4,2] | |
// 5 -> [5] | |
// 6 -> [5,1] | |
// 7 -> [5,2] | |
// 8 -> [5,2,1] | |
// 9 -> [5,2,2] | |
// 10 -> [10] | |
// 11 -> [10,1] | |
// 12 -> [10,2] | |
// 13 -> [10,2,1] | |
// 14 -> [10,2,2] | |
// 15 -> [10,5] | |
// 16 -> [10,5,1] | |
// 17 -> [10,5,2] | |
// 18 -> [10,5,2,1] | |
// 19 -> [10,5,2,2] | |
// 20 -> [10,10] | |
// 21 -> [10,10,1] | |
// 1,2,5,10 | |
while(number > 0) | |
{ | |
int n_10 = number / 10; | |
for(int i = 0; i < n_10;i++) | |
{ | |
result.append(10); | |
number = number - 10; | |
} | |
int n_5 = number / 5; | |
for(int i = 0; i < n_5;i++) | |
{ | |
result.append(5); | |
number = number - 5; | |
} | |
int n_2 = number / 2; | |
for(int i = 0; i < n_2;i++) | |
{ | |
result.append(2); | |
number = number - 2; | |
} | |
int n_1 = number / 1; | |
for(int i = 0; i < n_1;i++) | |
{ | |
result.append(1); | |
number = number - 1; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment