VLAN资源池
标题:VLAN资源池 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
VLAN是一种对局域网设备进行逻辑划分的技术,为了标识不同的VLAN,引入VLAN ID(1-4094之间的整数)的概念。定义一个VLAN ID的资源池(下称VLAN资源池),资源池中连续的VLAN用开始VLAN-结束VLAN表示,不连续的用单个整数表示,所有的VLAN用英文逗号连接起来。现在有一个VLAN资源池,业务需要从资源池中申请一个VLAN,需要你输出从VLAN资源池中移除申请的VLAN后的资源池。
def set_false(start, end, data_a): for i in range(start, end+1): data_a[i] = True if __name__ == '__main__': data_all = [False for i in range(4095)] data_in = input().strip().split(',') v_id = int(input().strip()) for i in data_in: if '-' in i: i_data = i.split('-') set_false(int(i_data[0]),int(i_data[1]),data_all) else: data_all[int(i)] = True data_all[v_id] = False res = '' i = 1 while i < 4095: if data_all[i]: count = 1 for j in range(i+1,4095): if data_all[j]: count += 1 else: break if count > 1: res += str(i)+'-'+str(i + count - 1)+',' i += count - 1 else: res += str(i)+',' i += 1 print(res[:-1])