php做网站需要html,仿 wordpress,17做网站联系,济南建设网站企业报价题目描述#xff1a; VLAN是一种对局域网设备进行逻辑划分的技术#xff0c;为了标识不同的VLAN#xff0c;引入VLAN ID(1-4094之间的整数)的概念。 定义一个VLAN ID的资源池(下称VLAN资源池)#xff0c;资源池中连续的VLAN用开始VLAN-结束VLAN表示#xff0c;不连续的用单… 
题目描述 VLAN是一种对局域网设备进行逻辑划分的技术为了标识不同的VLAN引入VLAN ID(1-4094之间的整数)的概念。 定义一个VLAN ID的资源池(下称VLAN资源池)资源池中连续的VLAN用开始VLAN-结束VLAN表示不连续的用单个整数表示所有的VLAN用英文逗号连接起来。现 在有一个VLAN资源池业务需要从资源池中申请一个VLAN需要你输出从VLAN资源池中移除申请的VLAN后的资源池。 
输入描述 
第一行为字符串格式的VLAN资源池 
第二行为业务要申请的VLANVLAN的取值范围为[1,4094]之间的整数。 
输出描述 从输入VLAN资源池中移除申请的VLAN后字符串格式的VLAN资源池输出要求满足题目描述中的格式并且按照VLAN从小到大升序输出。 如果申请的VLAN不在原VLAN资源池内输出原VLAN资源池升序排序后的字符串即可。 
备注 
输入VLAN资源池中VLAN的数量取值范围为[2-4094]间的整数资源池中VLAN不重复且合法([1,4094]之间的整数)输入是乱序的。 
示例 
输入 1-5          2 
输出 1,3-5 
说明 原VLAN资源池中有VLAN 1、2、3、4、5从资源池中移除2后剩下VLAN 1、3、4、5按照题目描述格式并升序后的结果为1,3-5。 输入 20-21,15,18,30,5-10        15 
输出 5-10,18,20-21,30 
说明 原VLAN资源池中有VLAN 5、6、7、8、9、10、15、18、20、21、30从资源池中移除15后资源池中剩下的VLAN为 5、6、7、8、9、10、18、20、21、30按照题目描述格式并升序后的结果为5-10,18,20-21,30。 
输入 5,1-3 10 
输出 1-3,5 
说明 原VLAN资源池中有VLAN 1、2、35申请的VLAN 10不在原资源池中将原资源池按照题目描述格式并按升序排序后输出的结果为1-3,5。 java 程序 
package com.tarena.test.B10; 
import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; import java.util.StringJoiner; import java.util.stream.Collectors; 
/**  *    题目描述 VLAN是一种对局域网设备进行逻辑划分的技术为了标识不同的VLAN引入VLAN ID(1-4094之间的整数)的概念。 定义一个VLAN ID的资源池(下称VLAN资源池)资源池中连续的VLAN用开始VLAN-结束VLAN表示不连续的用单个整数表示所有的VLAN用英文逗号连接起来。现 在有一个VLAN资源池业务需要从资源池中申请一个VLAN需要你输出从VLAN资源池中移除申请的VLAN后的资源池。 
输入描述 
第一行为字符串格式的VLAN资源池 
第二行为业务要申请的VLANVLAN的取值范围为[1,4094]之间的整数。 
输出描述 从输入VLAN资源池中移除申请的VLAN后字符串格式的VLAN资源池输出要求满足题目描述中的格式并且按照VLAN从小到大升序输出。 如果申请的VLAN不在原VLAN资源池内输出原VLAN资源池升序排序后的字符串即可。 
备注 
输入VLAN资源池中VLAN的数量取值范围为[2-4094]间的整数资源池中VLAN不重复且合法([1,4094]之间的整数)输入是乱序的。 
示例 
输入 1-5          2 
输出 1,3-5 
说明 原VLAN资源池中有VLAN 1、2、3、4、5从资源池中移除2后剩下VLAN 1、3、4、5按照题目描述格式并升序后的结果为1,3-5。 
输入 20-21,15,18,30,5-10        15 
输出 5-10,18,20-21,30 
说明 原VLAN资源池中有VLAN 5、6、7、8、9、10、15、18、20、21、30从资源池中移除15后资源池中剩下的VLAN为 5、6、7、8、9、10、18、20、21、30按照题目描述格式并升序后的结果为5-10,18,20-21,30。 
输入 5,1-3        10 
输出 1-3,5 
说明 原VLAN资源池中有VLAN 1、2、35申请的VLAN 10不在原资源池中将原资源池按照题目描述格式并按升序排序后输出的结果为1-3,5。  * author Administrator  *  */ public class B13 {               public static void main(String[] args) {         try(Scanner sc  new Scanner(System.in);){             String vlans  sc.nextLine();             Integer need  Integer.parseInt( sc.nextLine());             System.out.println(resultStr(vlans,need));         }     }          public static String resultStr(String vlans,Integer need) {         String[] vlanStr  vlans.split(,);         LinkedListInteger[] list  Arrays.stream(vlanStr).map(                 temp-Arrays.stream(temp.split(-)).map(Integer::parseInt).toArray(Integer[]::new))//         .sorted((a,b)- (a[0] - b[0]) )         .collect(Collectors.toCollection(LinkedList::new));         for(int i0;ilist.size();i) {             Integer[] tempArr  list.get(i);             if(tempArr.length1) {                 if(tempArr[0]need) {                     list.remove(i);                     break;                 }             }else {                 //比结尾大。结束本次循环                 if(needtempArr[1]) {                     continue;                 }                 //比开始小结束本次循环而且需要的数不存在                 if(needtempArr[0]) {                     break;                 }                 //结尾的值                 if(needtempArr[1]) {                     list.set(i, newArray(tempArr[0],tempArr[1]-1));//List 的set 方法与add方法这里可以变换使用。如果用add前面要先调用删除 remove(i);                 //开始的值                     }else if(needtempArr[0]){                     list.set(i, newArray(tempArr[0]1,tempArr[1]));                 }else {                     //list.remove(i);                     //先添加后面的数组                     list.set(i, newArray(need1,tempArr[1]));                     //再添加前面的数组刚添加的数组自动向后一位                     list.add(i, newArray(tempArr[0],need-1));                 }                 break;             }         }         //拼接字符串处理类         StringJoiner returnStr  new StringJoiner(,);         list.stream().map(arr -             { if(arr.length1) {//这一块有人也是用的 StringJoiner 来实现 大家觉得哪种方式好呢                             return arr[0]-arr[1];                             }else {                                 return arr[0];                             }                     }         ).forEach(returnStr::add);//temp1 - returnStr.add(temp1)         return returnStr.toString();     } public static Integer[] newArray(Integer begin,Integer end) {         if(begin  end) {             return new Integer[] {begin,end};         }else {             return new Integer[] {begin};         }     } } 了解知识点 
1、StringJoiner 类之前自己写过类似的功能类但是不知道java自带的这个类 
2、Arrays 感觉很久没有用这个工具类专门处理数组的类 
3、Stream 流的使用 里面的.map(), .sort(),.collect()等发放使用还有.forEach等方法 文章转载自: http://www.morning.mdrnn.cn.gov.cn.mdrnn.cn http://www.morning.lggng.cn.gov.cn.lggng.cn http://www.morning.xlxmy.cn.gov.cn.xlxmy.cn http://www.morning.wdlyt.cn.gov.cn.wdlyt.cn http://www.morning.ykklw.cn.gov.cn.ykklw.cn http://www.morning.jnptt.cn.gov.cn.jnptt.cn http://www.morning.pqxjq.cn.gov.cn.pqxjq.cn http://www.morning.ryxbz.cn.gov.cn.ryxbz.cn http://www.morning.ncwgt.cn.gov.cn.ncwgt.cn http://www.morning.wcczg.cn.gov.cn.wcczg.cn http://www.morning.jxpwr.cn.gov.cn.jxpwr.cn http://www.morning.twdwy.cn.gov.cn.twdwy.cn http://www.morning.dmzqd.cn.gov.cn.dmzqd.cn http://www.morning.juju8.cn.gov.cn.juju8.cn http://www.morning.fglyb.cn.gov.cn.fglyb.cn http://www.morning.thmlt.cn.gov.cn.thmlt.cn http://www.morning.bwjws.cn.gov.cn.bwjws.cn http://www.morning.flzqq.cn.gov.cn.flzqq.cn http://www.morning.wmdqc.com.gov.cn.wmdqc.com http://www.morning.rykx.cn.gov.cn.rykx.cn http://www.morning.bpmfg.cn.gov.cn.bpmfg.cn http://www.morning.gbfck.cn.gov.cn.gbfck.cn http://www.morning.hctgn.cn.gov.cn.hctgn.cn http://www.morning.jjhrj.cn.gov.cn.jjhrj.cn http://www.morning.yslfn.cn.gov.cn.yslfn.cn http://www.morning.rywr.cn.gov.cn.rywr.cn http://www.morning.kcwkt.cn.gov.cn.kcwkt.cn http://www.morning.hnrpk.cn.gov.cn.hnrpk.cn http://www.morning.tdmr.cn.gov.cn.tdmr.cn http://www.morning.dlmqn.cn.gov.cn.dlmqn.cn http://www.morning.gbljq.cn.gov.cn.gbljq.cn http://www.morning.hwzzq.cn.gov.cn.hwzzq.cn http://www.morning.dbxss.cn.gov.cn.dbxss.cn http://www.morning.mhcys.cn.gov.cn.mhcys.cn http://www.morning.jfymz.cn.gov.cn.jfymz.cn http://www.morning.dbnpz.cn.gov.cn.dbnpz.cn http://www.morning.hlhqs.cn.gov.cn.hlhqs.cn http://www.morning.yrbp.cn.gov.cn.yrbp.cn http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn http://www.morning.lzdbb.cn.gov.cn.lzdbb.cn http://www.morning.jrsgs.cn.gov.cn.jrsgs.cn http://www.morning.dmzfz.cn.gov.cn.dmzfz.cn http://www.morning.hkswt.cn.gov.cn.hkswt.cn http://www.morning.kmprl.cn.gov.cn.kmprl.cn http://www.morning.lsjtq.cn.gov.cn.lsjtq.cn http://www.morning.jnvivi.com.gov.cn.jnvivi.com http://www.morning.ljzqb.cn.gov.cn.ljzqb.cn http://www.morning.bfhfb.cn.gov.cn.bfhfb.cn http://www.morning.inheatherskitchen.com.gov.cn.inheatherskitchen.com http://www.morning.xrqkm.cn.gov.cn.xrqkm.cn http://www.morning.xbhpm.cn.gov.cn.xbhpm.cn http://www.morning.yggdq.cn.gov.cn.yggdq.cn http://www.morning.nzqmw.cn.gov.cn.nzqmw.cn http://www.morning.spwln.cn.gov.cn.spwln.cn http://www.morning.bnlsd.cn.gov.cn.bnlsd.cn http://www.morning.jxtbr.cn.gov.cn.jxtbr.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.qflwp.cn.gov.cn.qflwp.cn http://www.morning.nrgdc.cn.gov.cn.nrgdc.cn http://www.morning.wftrs.cn.gov.cn.wftrs.cn http://www.morning.brld.cn.gov.cn.brld.cn http://www.morning.touziyou.cn.gov.cn.touziyou.cn http://www.morning.sgnxl.cn.gov.cn.sgnxl.cn http://www.morning.tnbas.com.gov.cn.tnbas.com http://www.morning.rnribht.cn.gov.cn.rnribht.cn http://www.morning.ghlyy.cn.gov.cn.ghlyy.cn http://www.morning.wnxqf.cn.gov.cn.wnxqf.cn http://www.morning.jrksk.cn.gov.cn.jrksk.cn http://www.morning.kjdxh.cn.gov.cn.kjdxh.cn http://www.morning.cfmrb.cn.gov.cn.cfmrb.cn http://www.morning.htbsk.cn.gov.cn.htbsk.cn http://www.morning.mwhqd.cn.gov.cn.mwhqd.cn http://www.morning.ttkns.cn.gov.cn.ttkns.cn http://www.morning.sqnrz.cn.gov.cn.sqnrz.cn http://www.morning.jrqcj.cn.gov.cn.jrqcj.cn http://www.morning.xbnkm.cn.gov.cn.xbnkm.cn http://www.morning.yprnp.cn.gov.cn.yprnp.cn http://www.morning.rryny.cn.gov.cn.rryny.cn http://www.morning.xkjqg.cn.gov.cn.xkjqg.cn http://www.morning.qjlnh.cn.gov.cn.qjlnh.cn