def test(ary): ds = {} for i in range(len(ary)): if ds.get(ary[i]): ds[ary[i]].append(i) else: ds[ary[i]] = [i] return ds if __name__ == '__main__': ary = [1,2,3,5,2,5,4] ds = test(ary) num = int(input("which number you want?")) print(ds[num]) 其…
给定数组a[1,2,3],用a里面的元素来生成一个长度为5的数组,打印出其排列组合 ruby代码: def all_possible_arr arr, length = 5 ret = [] length.times do if ret.empty? ret = arr.map {|i| [i]} else new_ret = [] ret.each do |r| arr.each do |e| new_ret << r.clone.unshift(e) end end ret = new_r…
C - Grand Garden In a flower bed, there are NN flowers, numbered 1,2,......,N1,2,......,N. Initially, the heights of all flowers are 00. You are given a sequence h={h1,h2,h3,......}h={h1,h2,h3,......} as input. You would like to change the height of…