Java教程

2021中国农业银行(浙江省分信息科技岗)春季校园招聘笔试编程题及答案解析(待更)

本文主要是介绍2021中国农业银行(浙江省分信息科技岗)春季校园招聘笔试编程题及答案解析(待更),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

2021中国农业银行春季校园招聘笔试共计三道编程题题目,详解如下:

题目一

def list_to_set(ls):
    len_ls = ls[-1] - ls[0]
    ls0 = [ls[0]]
    for i in range(len_ls):
        ls1 = ls[0] + i + 1
        ls0.append(ls1)
    set0 = set(ls0)
    return set0

# print(list_to_set([3,4]))

def merge_sets(set_list):
    if len(set_list) == 0:
        # short circuit to avoid errors
        return []

    current_set = set_list[0]
    new_set_list = [current_set, ]

    for s in set_list[1:]:          # iterate from the second element
        if len(current_set.intersection(s)) > 0:
            current_set.update(s)
        else:
            current_set = set(s)    # copy
            new_set_list.append(current_set)
            
    return new_set_list

import sys
s = int(sys.stdin.readline())
ans = []
for i in range(s):
    l = input().split()
    temp = [int(j) for j in l]
    ans.append(list_to_set(temp))

print(ans)
print(merge_sets(ans))
print(s - len(merge_sets(ans)))

3
2 4
3 5
6 7
这篇关于2021中国农业银行(浙江省分信息科技岗)春季校园招聘笔试编程题及答案解析(待更)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!