1class Solution {2public:3bool checkforIPv6(string IP) {4int n = IP.size();5vector<string> store;6string s = "";7for (int i = 0; i < n; i++) {8if (IP[i] == ':') {9store.push_back(s);10s = "";11} else {12s += IP[i];13}14}15store.push_back(s);16if (store.size() != 8) {17return false;18}19for (int i = 0; i < store.size(); i++) {20string s = store[i];21if (s.size() > 4 or s.size() == 0) {22return false;23}24for (int j = 0; j < s.size(); j++) {25if (s[j] >= 'a' and s[j] <= 'f') {26continue;27} else if (s[j] >= 'A' and s[j] <= 'F') {28continue;29} else if (s[j] >= '0' and s[j] <= '9') {30continue;31} else {32return false;33}34}35}36return true;37}3839bool checkforIPv4(string IP) {40int n = IP.size();41vector<string> store;42string s = "";43for (int i = 0; i < n; i++) {44if (IP[i] == '.') {45store.push_back(s);46s = "";47} else {48s += IP[i];49}50}51store.push_back(s);52if (store.size() != 4) {53return false;54}55for (int i = 0; i < store.size(); i++) {56string s = store[i];57if (s.size() > 3 or s.size() == 0) {58return false;59}60int num = 0;61for (int j = 0; j < s.size(); j++) {62if (s.size() >= 2 and s[0] == '0' and s[1] == '0') {63return false;64}65if (s.size() >= 2 and s[0] == '0' and s[1] != '0') {66return false;67}68if (s[j] >= '0' and s[j] <= '9') {69// Do nothing.70} else {71return false;72}73num = num * 10 + (s[j] - '0');74}75if (num > 255 or num < 0) {76return false;77}78}79return true;80}81string validIPAddress(string queryIP) {82bool IPv6 = checkforIPv6(queryIP);83bool IPv4 = checkforIPv4(queryIP);84if (IPv6) {85return "IPv6";86}87if (IPv4) {88return "IPv4";89}90return "Neither";91}92};