From 2f30daabd2413f267de039e95f435be4a89a2406 Mon Sep 17 00:00:00 2001 From: bala <13452927+rfgsdhshgfh@user.noreply.gitee.com> Date: Sat, 13 Jan 2024 15:13:01 +0000 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8DIP=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bala <13452927+rfgsdhshgfh@user.noreply.gitee.com> --- ...345\244\215IP\345\234\260\345\235\200.cpp" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "2224020152/\347\254\254\344\272\224\345\215\225\345\205\203/\346\201\242\345\244\215IP\345\234\260\345\235\200.cpp" diff --git "a/2224020152/\347\254\254\344\272\224\345\215\225\345\205\203/\346\201\242\345\244\215IP\345\234\260\345\235\200.cpp" "b/2224020152/\347\254\254\344\272\224\345\215\225\345\205\203/\346\201\242\345\244\215IP\345\234\260\345\235\200.cpp" new file mode 100644 index 00000000..d788267e --- /dev/null +++ "b/2224020152/\347\254\254\344\272\224\345\215\225\345\205\203/\346\201\242\345\244\215IP\345\234\260\345\235\200.cpp" @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +string s; +set result; +void getIP(string temp,int st,int en,int time) +{ + if(en>s.size()) + return ; + if(time>3) + return ; + string sub=s.substr(st,en-st); + if(sub[0]=='0'&&sub.size()>1) + return ; + int num=atoi(sub.substr(0,en-st).c_str()); + if(num>255) + return ; + temp+=sub; + if(en!=s.size()) + temp+="."; + else + { + if(time==3) + result.insert(temp); + return ; + } + getIP(temp,en,en+1,time+1); + getIP(temp,en,en+2,time+1); + getIP(temp,en,en+3,time+1); +} +void printfIP() + if(result.empty()) + { + printf("输入不合法\n"); + } + else + { + set ::iterator a; + printf("可能有效的IP地址有:\n"); + for(a=result.begin();a!=result.end();a++) + cout<<*a<>s; + string temp=""; + getIP(temp,0,1,0); + getIP(temp,0,2,0); + getIP(temp,0,3,0); + printfIP(); + printf("继续请输入1,退出操作请输入0\n"); + cin>>num; + if(num==0) + break; + else + continue; + } + return 0; +} \ No newline at end of file -- Gitee