dlum1085-打表

这是一道打表题,我在打表的程序里主要使用到了二叉树来实现:根节点为空节点,4为根的左子,7为根的右子,用数组来实现树:a[ i ] = a[ i/2 ]*10+a[ i%2+2 ],a[2]=4,a[3]=7;循环条件为i=1024。之后就是main的处理了,注意到数据很大,不能直接用加来求,而要通过在(a[i+1]-a[i])*a[i+1]来求,不过要注意l与r和a[i]之间的大小。

打表程序:

#include<cstdio>
#include<iostream>
#include<cstring>

using namespace std;

const int maxn=10000;
int a[maxn];

int main()
{
    freopen("out.txt","w",stdout);
    memset(a,0,sizeof(a));
    a[1]=0;
    a[2]=4;a[3]=7;
    printf("4,7,");
    for(int i=4;i<1025;i++){
        a[i]=a[i/2]*10+a[i%2+2];
        printf("%d,",a[i]);
    }
    printf("4444444444\n");
    return 0;
}

提交程序:

#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=1100;
long long a[maxn]={4,7,44,47,74,77,444,447,474,477,744,747,774,777,4444,4447,4474,4477,4744,4747,4774,4777,7444,7447,
7474,7477,7744,7747,7774,7777,44444,44447,44474,44477,44744,44747,44774,44777,47444,47447,47474,47477,47744,47747,47774,
47777,74444,74447,74474,74477,74744,74747,74774,74777,77444,77447,77474,77477,77744,77747,77774,77777,444444,444447,444474,
444477,444744,444747,444774,444777,447444,447447,447474,447477,447744,447747,447774,447777,474444,474447,474474,474477,474744,
474747,474774,474777,477444,477447,477474,477477,477744,477747,477774,477777,744444,744447,744474,744477,744744,744747,744774,
744777,747444,747447,747474,747477,747744,747747,747774,747777,774444,774447,774474,774477,774744,774747,774774,774777,777444,
777447,777474,777477,777744,777747,777774,777777,4444444,4444447,4444474,4444477,4444744,4444747,4444774,4444777,4447444,4447447,
4447474,4447477,4447744,4447747,4447774,4447777,4474444,4474447,4474474,4474477,4474744,4474747,4474774,4474777,4477444,4477447,
4477474,4477477,4477744,4477747,4477774,4477777,4744444,4744447,4744474,4744477,4744744,4744747,4744774,4744777,4747444,4747447,
4747474,4747477,4747744,4747747,4747774,4747777,
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值