C++ program to generate all possible
// valid IP addresses from given string
// Function checks whether IP digits
// are valid or not.
int is_valid(string ip)
{
// Splitting by "."
vector <string> ips;
string ex = "";
for(int i = 0; i < ip.size(); i++)
{
if (ip[i] == '.')
{
ips.push_back(ex);
ex = "";
}
Else
{
ex = ex + ip[i];
}
}
ips.push_back(ex);
// Checking for the corner cases
// cout << ip << endl;
for(int i = 0; i < ips.size(); i++)
{
// cout << ips[i] <<endl;
if( ips[i].length() > 3 ||
stoi(ips[i]) < 0 ||
stoi(ips[i]) > 255 )
return 0;