HDU5138 CET-6 test && BestCoder Round #21 1001

来源:互联网 发布:富二代体验知乎 编辑:程序博客网 时间:2024/06/05 10:28

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5138

题思路:BestCoder官方题解:

直接从1到n枚举i,判断n-i是否与1,2,4,7,15相等复杂度o(n)
水题,直接上代码:

AC代码:

#include<iostream>#include<cstdio>using namespace std;int main(){    int n;    int b[]={1,2,4,7,15};    while(scanf("%d",&n)!=EOF)    {        int i,j=0,t=n,a[5];        for(i=0;i<5;i++)        {            if(n-b[i]<1)                break;            a[i]=n-b[i];        }        for(i--;i>0;i--)            printf("%d ",a[i]);        printf("%d\n",a[i]);    }    return 0;}


0 0