Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
139853 | 陈家宝 | 复原 IP 地址 | C++ | 通过 | 100 | 0 MS | 252 KB | 684 | 2024-03-26 13:47:00 |
#include<bits/stdc++.h> using namespace std; int n; string s; vector<string> res; void dfs(int k,int cnt,string& s,string str){ if(k==n&&cnt==4){ res.push_back(str); res.push_back("\n"); } if(k==n||cnt==4)return; if(cnt>0)str+='.'; int num=0,rem; string temp; for(int i=k;i<n;i++){ num=num*10+s[i]-'0'; if(num>255)break; temp+=s[i]; rem=n-1-i; if(rem>=3-cnt&&rem<=3*(3-cnt))dfs(i+1,cnt+1,s,str+temp); if(num==0)break; } } int main(){ cin>>s; n=s.size(); if(n<4||n>12)return 0; dfs(0,0,s,""); for(int i=0;i<res.size();i++)cout<<res[i]; return 0; }