本文介绍了算法匹配数组中的数字与数组中的任何其他数字加上lenth(该数字的二进制表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设数n支持数字(n + x),其中x是n的二进制表示中的比特数,如果n = 10,其二进制表示为1010,即x = 4;然后它支持(10 + 4)= 14。现在,在问题中,您将获得一系列数字。如果数字由列表中的任何数字X支持,则必须打印由数字(X)支持,如果没有这样的数字,则必须打印NOT SUPPORTED。如果数组具有重复条目,则该函数应打印Number'X'具有重复条目。如何在python中构建逻辑



我尝试过:



  def  numberSup(A):
dict_1 = [] * 1000
list_a = []
set_a =()
A.sort()
k = list(( {0:b} .format(i) for i in A))
gen = list((int(i) for i in k))
if len(set(gen))!= len(A):
print 不允许复制元素),A, gen

for i in A:
for j in gen:
key = i + len( str(j))





现在,当我遍历两个列表时,我将如何存储两个列表中的总和,即A和gen 。?

解决方案

然后,这就是答案 [ ^

Let, a number n support a number (n+x), where x is the number of bits in the binary representation of n, like if n = 10, whose binary representation is 1010, i.e x=4; then it supports (10+4)=14. Now, in the questions, you are provided with an array of numbers. You have to print "SUPPORTED BY THE NUMBER (X)" if number is supported by any number 'X ' in the list and "NOT SUPPORTED" if there are no such number. If the array has duplicate entry, the function should print "Number 'X' has duplicate entry". How can i build the logic in python

What I have tried:

def numberSup(A):
dict_1 = []*1000
list_a = []
set_a = ()
A.sort()
k = list(("{0:b}".format(i) for i in A))
gen = list((int(i) for i in k))
if len(set(gen))!= len(A):
    print("Duplicate Elements are not allowed"),A,gen

for i in A:
    for j in gen:
        key =  i + len(str(j))



Now How will i store the sum from both the lists as i traverse through both of them namely A and gen.?

解决方案

then, this is the answer How do I add two lists together to create one final list[^]


这篇关于算法匹配数组中的数字与数组中的任何其他数字加上lenth(该数字的二进制表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 14:52