Advertisement
mssroot

ip address

Nov 26th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9. typedef vector<ll> vll;
  10.  
  11. ll i, j;
  12. string str;
  13. vll dot, param;
  14.  
  15. string check()
  16. {
  17.     if (param.size() != 4) return "Bad";
  18.     for (i = 0; i < 4; i++) if (dot[i + 1] - dot[i] == 1) return "Bad";
  19.     for (i = 0; i < 4; i++) if (param[i] > 255) return "Bad";
  20.     return "Good";
  21. }
  22.  
  23. int main()
  24. {
  25.     getline(cin, str);
  26.     dot.push_back(-1);
  27.     for (i = 1; i < str.length() - 1; i++) if (str[i] == '.') dot.push_back(i);
  28.     dot.push_back(str.length());
  29.     if (dot.size() == 5)
  30.     {
  31.         for (i = 0; i < 4; i++)
  32.         {
  33.             param.push_back(0);
  34.             for (j = dot[i] + 1; j < dot[i + 1]; j++) param[i] = param[i] * 10 + str[j] - 48;
  35.         }
  36.     }
  37.     cout << check() << endl;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement