Sum of 4 Integers
Aizu - 0008Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤a, b, c, d ≤ 9) which meet the following equality:
a + b + c + d = n
For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
Input
The input consists of several datasets. Each dataset consists of n (1 ≤ n ≤ 50) in a line. The number of datasets is less than or equal to 50.
Output
Print the number of combination in a line.
Sample Input
35 1
Output for the Sample Input
4 4
问题链接:AOJ0008 Sum of 4 Integers
问题简述:(略)
问题分析:求组合数问题,暴力法是最基本的一种方法。
程序说明:(略)
题记:(略)参考链接:(略)
AC的C语言程序如下:
/* AOJ0008 Sum of 4 Integers */
#include <stdio.h>
#define ZERO 0
#define NINE 9
int main(void)
{
int n, cnt, i, j, k, l;
while(~scanf("%d", &n)) {
cnt = 0;
for(i=ZERO; i<=NINE; i++)
for(j=ZERO; j<=NINE; j++)
for(k=ZERO; k<=NINE; k++)
for(l=ZERO; l<=NINE; l++)
if(i + j + k + l == n)
cnt++;
printf("%d\n", cnt);
}
return 0;
}