what is the correct/required headers to have for c++ code?

  • Thread starter Thread starter abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL
  • Start date Start date
A

abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL

Guest
here is my c++code:

#include <set-location; ip address generator.exe location= C:\Users\yda\ip
using namespace std;
{

int main()
}
// 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 == '.')
{
ips.push_back(ex);
ex = "";
}
else
{
ex = ex + ip;
}
}
ips.push_back(ex);

// Checking for the corner cases
// cout << ip << endl;
for(int i = 0; i < ips.size(); i++)
{
// cout << ips <<endl;
if( ips.length() > 3 ||
stoi(ips) < 0 ||
stoi(ips) > 255 )
return 0;

if( ips.length() > 1 &&
stoi(ips) == 0)
return 0;

if( ips.length() > 1 &&
stoi(ips) != 0 &&
ips[0] == '0')
return 0;
}
return 1;
}

// Function converts string to IP address
void convert(string ip)
{
int l = ip.length();

// Check for string size
if ( l>12 || l<4 )
{
cout << "Not Valid IP Address";
}

string check = ip;
vector <string> ans;

// Generating different combinations.
for( int i = 1; i < l - 2; i++ )
{
for( int j = i + 1; j < l - 1; j++ )
{
for( int k = j + 1; k < l; k++ )
{
check = check.substr(0, k) + "." +
check.substr(k, l - k + 2);
check = check.substr(0, j) + "." +
check.substr(j, l - j + 3);
check = check.substr(0, i) + "." +
check.substr(i, l - i + 4);

// cout<< check <<endl;
// Check for the validity of combination
if (is_valid(check))
{
ans.push_back (check);
std::cout << check << '\n';
}
check = ip;
}
}
}
}

// Driver code
int main()
{
string A = "25525511135";
string B = "25505011535";

convert(A);
convert(B);

return 0;
}

Continue reading...
 
Back
Top