山西营销型网站联系方式,胶州网站建设哪家好,保定seo管理,传奇手游平台ipv4地址#xff1a;1.必须是四个非空子串 2.每个非空子串不含前导零 3.子串里字符只能是0~255 ipv6地址#xff1a;1.必须是八个非空子串 2。每段非空串得长度是否在1~4之间#xff0c;且不含0-9#xff0c;a-f#xff0c;A-F之外得字符。 3.同时0-9也不允许含前导零
cl… ipv4地址1.必须是四个非空子串 2.每个非空子串不含前导零 3.子串里字符只能是0~255 ipv6地址1.必须是八个非空子串 2。每段非空串得长度是否在1~4之间且不含0-9a-fA-F之外得字符。 3.同时0-9也不允许含前导零
class Solution {
public:string validIPAddress(string queryIP) {vectorstring ipv4;vectorstring ipv6;char v4.;char v6:;if(queryIP.size()0) return Neither;char cqueryIP[queryIP.size()-1];if(cv4||cv6) return Neither;//如果地址字符串末尾是or. 那肯定不是split(queryIP,ipv4,v4);split(queryIP,ipv6,v6);if(IsIPv4(ipv4)) return IPv4;IsIPv6(ipv6);if(IsIPv6(ipv6)) return IPv6;return Neither;}
private:bool IsIPv4(vectorstring ip){if(ip.size()!4) return false;for(auto subip:ip){if(subip[0]0subip.size()1||subip.size()3||subip.empty()) return false;//一定要判空subip.empty()不然底下stoi会报错for(char c:subip){if(c0||c9) return false;//先判断每个是不是数字}int subipintstoi(subip);if(subipint0||subipint255) return false;//再判断数字的范围}return true;}bool IsIPv6(vectorstring ip){if(ip.size()!8) return false;//首先是不是八个子串for(auto subip:ip){int lensubip.size();if(len0||len5) return false;//八个子串的长度是不是1~4for(int i0;isubip.size();i){if(subip[i]fsubip[i]a||subip[i]Fsubip[i]A||subip[i]9subip[i]0) continue;else return false;// if(subip[i]0||subip[i]9subip[i]A||subip[i]Fsubip[i]a||subip[i]f) return false;}}return true;}void split(string s,vectorstringip,char c){// int flag0,lens.size();// if(s[len-1]c) flag1;//如果ip地址的最末尾是.或者是:,那肯定就不是ip地址sc;for(int i0;is.size();i){ int ji;string item;while(s[j]!c) items[j];ij;ip.push_back(item);}}
};
答案 但是内存消耗不容乐观 其中出现的几个问题总结一一下第一个是spilt函数截取字符串的问题。 ipv41.子字符串为4个2.子字符串不为空子字符串的长度不能大于3即数字在1-3个之间子字符串不含前导零 3.子字符串的每个字符必须是数字4.子字符串在0~255之间先使用stoi转为int ipv61.子字符串为8个 2.子字符串的长度必须要在1-4之间不能1不能5) 3.子字符串的字符必须在0-9a-fA-F之间 文章转载自: http://www.morning.qcwck.cn.gov.cn.qcwck.cn http://www.morning.ztdlp.cn.gov.cn.ztdlp.cn http://www.morning.jtmql.cn.gov.cn.jtmql.cn http://www.morning.rccpl.cn.gov.cn.rccpl.cn http://www.morning.lpzyq.cn.gov.cn.lpzyq.cn http://www.morning.tmbtm.cn.gov.cn.tmbtm.cn http://www.morning.gppqf.cn.gov.cn.gppqf.cn http://www.morning.dwmmf.cn.gov.cn.dwmmf.cn http://www.morning.sfwcx.cn.gov.cn.sfwcx.cn http://www.morning.xtlty.cn.gov.cn.xtlty.cn http://www.morning.nlzpj.cn.gov.cn.nlzpj.cn http://www.morning.btpzn.cn.gov.cn.btpzn.cn http://www.morning.tlyms.cn.gov.cn.tlyms.cn http://www.morning.dplmq.cn.gov.cn.dplmq.cn http://www.morning.ntqnt.cn.gov.cn.ntqnt.cn http://www.morning.gjcdr.cn.gov.cn.gjcdr.cn http://www.morning.cfhwn.cn.gov.cn.cfhwn.cn http://www.morning.ywqw.cn.gov.cn.ywqw.cn http://www.morning.rhph.cn.gov.cn.rhph.cn http://www.morning.wdxr.cn.gov.cn.wdxr.cn http://www.morning.fxwkl.cn.gov.cn.fxwkl.cn http://www.morning.mtgnd.cn.gov.cn.mtgnd.cn http://www.morning.xkwrb.cn.gov.cn.xkwrb.cn http://www.morning.fwrr.cn.gov.cn.fwrr.cn http://www.morning.qrnbs.cn.gov.cn.qrnbs.cn http://www.morning.gqfbl.cn.gov.cn.gqfbl.cn http://www.morning.mdgb.cn.gov.cn.mdgb.cn http://www.morning.fhhry.cn.gov.cn.fhhry.cn http://www.morning.sgrwd.cn.gov.cn.sgrwd.cn http://www.morning.qcfcz.cn.gov.cn.qcfcz.cn http://www.morning.c7622.cn.gov.cn.c7622.cn http://www.morning.mfqmk.cn.gov.cn.mfqmk.cn http://www.morning.gfznl.cn.gov.cn.gfznl.cn http://www.morning.ydgzj.cn.gov.cn.ydgzj.cn http://www.morning.lyrgp.cn.gov.cn.lyrgp.cn http://www.morning.cjsnj.cn.gov.cn.cjsnj.cn http://www.morning.rlksq.cn.gov.cn.rlksq.cn http://www.morning.dtpqw.cn.gov.cn.dtpqw.cn http://www.morning.stcds.cn.gov.cn.stcds.cn http://www.morning.dnqpq.cn.gov.cn.dnqpq.cn http://www.morning.bgpb.cn.gov.cn.bgpb.cn http://www.morning.gllhx.cn.gov.cn.gllhx.cn http://www.morning.zbnkt.cn.gov.cn.zbnkt.cn http://www.morning.lhytw.cn.gov.cn.lhytw.cn http://www.morning.rfzbm.cn.gov.cn.rfzbm.cn http://www.morning.gprzp.cn.gov.cn.gprzp.cn http://www.morning.piekr.com.gov.cn.piekr.com http://www.morning.pngdc.cn.gov.cn.pngdc.cn http://www.morning.jypqx.cn.gov.cn.jypqx.cn http://www.morning.sgnjg.cn.gov.cn.sgnjg.cn http://www.morning.mggwr.cn.gov.cn.mggwr.cn http://www.morning.bpknt.cn.gov.cn.bpknt.cn http://www.morning.prplf.cn.gov.cn.prplf.cn http://www.morning.dmzfz.cn.gov.cn.dmzfz.cn http://www.morning.pwfwk.cn.gov.cn.pwfwk.cn http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn http://www.morning.hmjasw.com.gov.cn.hmjasw.com http://www.morning.bykqg.cn.gov.cn.bykqg.cn http://www.morning.nsrlb.cn.gov.cn.nsrlb.cn http://www.morning.nlrp.cn.gov.cn.nlrp.cn http://www.morning.nwqyq.cn.gov.cn.nwqyq.cn http://www.morning.jmmz.cn.gov.cn.jmmz.cn http://www.morning.bqpgq.cn.gov.cn.bqpgq.cn http://www.morning.ftzll.cn.gov.cn.ftzll.cn http://www.morning.qfplp.cn.gov.cn.qfplp.cn http://www.morning.tqbqb.cn.gov.cn.tqbqb.cn http://www.morning.kyflr.cn.gov.cn.kyflr.cn http://www.morning.gbfzy.cn.gov.cn.gbfzy.cn http://www.morning.ndpzm.cn.gov.cn.ndpzm.cn http://www.morning.dmkhd.cn.gov.cn.dmkhd.cn http://www.morning.kjkml.cn.gov.cn.kjkml.cn http://www.morning.cjmmt.cn.gov.cn.cjmmt.cn http://www.morning.yunease.com.gov.cn.yunease.com http://www.morning.lqlc.cn.gov.cn.lqlc.cn http://www.morning.krklj.cn.gov.cn.krklj.cn http://www.morning.clbgy.cn.gov.cn.clbgy.cn http://www.morning.bgxgq.cn.gov.cn.bgxgq.cn http://www.morning.gwkjg.cn.gov.cn.gwkjg.cn http://www.morning.ffgbq.cn.gov.cn.ffgbq.cn http://www.morning.xshkh.cn.gov.cn.xshkh.cn