huangjian


私信TA

用户名:dotcpp0626587

访问量:543

签 名:

等  级
排  名 9902
经  验 1067
参赛次数 1
文章发表 15
年  龄 0
在职情况 教师
学  校
专  业

  自我简介:

#问题:分解n (大)-----分解n的二进制(小)

def rec(n):

    for x in range(14,-1,-1):

        s=n-pow(2,x)

        if s>0:

            if x==2:

                print("2(2)+",end='')

            elif x==1:

                print("2+",end='')

            elif x==0:

                print("2(0)+",end='')

            else:

                print("2(",end='')

                rec(x)

                print(")+",end='')

            n=s        

        if s==0:

            if x==1:

                print("2",end='')

                return

            elif x==0:

                print("2(0)",end='')

                return

            else :

                print("2(",end='')

                rec(x)

                print(")",end='')

                return


n=int(input())

rec(n)


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区