题解 | #IP地址#
IP地址
https://www.nowcoder.com/practice/2359e23180194f99828f5cd9c764236a
#include <iostream>
#include <string>
using namespace std;
int main() {
string id;
while (cin >> id) {
bool flag = false;
id += '.';
for (int i = 0, j = 0, k = 0, n = id.size(); j < n; ++j) {
if (id[j] != '.') continue;
else {
int val = stoi(id.substr(i, j - i));
if (0 > val || 255 < val) break;
i = j + 1;
if (++k == 4) flag = true;
}
}
cout << (flag ? "Yes!" : "No!") << endl;
}
}
// 64 位输出请用 printf("%lld")
查看5道真题和解析