题解 | #IP地址#
IP地址
https://www.nowcoder.com/practice/2359e23180194f99828f5cd9c764236a
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
int main() {
string str;
getline(cin, str);
int flag = 1;
string result;
for (int i = 0; i < str.size(); i++) {
if (str[i] == '.' ) {
if (stoi(result) > 255 || stoi(result) < 0) {
flag = 0;
break;
}
else {
result = "";
}
}
else {
result += str[i];
}
}
if (stoi(result) > 255 || stoi(result) < 0)
flag = 0;
if (flag == 1)
printf("Yes!");
else
printf("No!");
}