AOJ0008 Sum of 4 Integers【暴力】

Sum of 4 Integers

  Aizu - 0008 

Write 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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值