homework02.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """
  2. 模拟面试编程题
  3. """
  4. def second_max(items: list, gt=lambda x, y: x > y):
  5. """从列表中找出第二大元素"""
  6. assert len(items) >= 2
  7. max1, max2 = (items[0], items[1]) \
  8. if gt(items[0], items[1]) else (items[1], items[0])
  9. for i in range(2, len(items)):
  10. if gt(max1, items[i]) and gt(items[i], max2):
  11. max2 = items[i]
  12. elif gt(items[i], max1):
  13. max1, max2 = items[i], max1
  14. return max2
  15. def list_depth(items: list) -> int:
  16. """计算嵌套列表的嵌套深度"""
  17. if isinstance(items, list):
  18. max_depth = 1
  19. for item in items:
  20. max_depth = max(list_depth(item) + 1, max_depth)
  21. return max_depth
  22. return 0
  23. def main():
  24. """主函数"""
  25. one_set = {1}
  26. pos, off = 1, 1
  27. while pos <= 100000000:
  28. pos += off
  29. one_set.add(pos)
  30. off += 1
  31. num, *poses = map(int, input().split())
  32. for pos in poses:
  33. print(1 if pos in one_set else 0, end=' ')
  34. # items1 = [38, 95, 27, 95, 88, 73, 61, 50]
  35. # print(second_max(items1))
  36. # items2 = [[1], [[[2]]],[[3]], 4, [[[[[5, [6]]]]]]]
  37. # print(list_depth(items1))
  38. # print(list_depth(items2))
  39. if __name__ == '__main__':
  40. main()