#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cctype>
// 检查一个字符串是否是有效的IPv4地址
bool isValidIPv4(const std::string& ip) {
std::vector<std::string> segments;
std::stringstream ss(ip);
std::string segment;
while (std::getline(ss, segment, '.')) {
segments.push_back(segment);
}
if (segments.size() != 4) {
return false;
}
for (const std::string& seg : segments) {
if (seg.empty() || seg.size() > 3 || !std::all_of(seg.begin(), seg.end(), ::isdigit)) {
return false;
}
if (seg[0] == '0' && seg.size() > 1) {
return false;
}
int num = std::stoi(seg);
if (num < 0 || num > 255) {
return false;
}
}
return true;
}
// 检查一个字符串是否是有效的IPv6地址
bool isValidIPv6(const std::string& ip) {
std::vector<std::string> segments;
std::stringstream ss(ip);
std::string segment;
while (std::getline(ss, segment, ':')) {
segments.push_back(segment);
}
if (segments.size() != 8) {
return false;
}
for (const std::string& seg : segments) {
if (seg.empty() || seg.size() > 4) {
return false;
}
for (char ch : seg) {
if (!isxdigit(ch)) {
return false;
}
}
}
// 检查是否有多余的冒号
if (ip.back() == ':') {
return false;
}
return true;
}
int main() {
std::string ip;
while (std::getline(std::cin, ip)) {
if (isValidIPv4(ip)) {
std::cout << "IPv4" << std::endl;
} else if (isValidIPv6(ip)) {
std::cout << "IPv6" << std::endl;
} else {
std::cout << "N" << std::endl;
}
}
return 0;
}