AcWing 3594. IP地址
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e6 + 10;
int t, n, m, k, l, r, op, x, y;
int f[N];
bool flag;
string str;
void solve() {
while (cin >> str) {
str.push_back('.');
flag = true;
x = 0;
for (char ch : str) {
if (ch == '.') {
if (x > 255) {
flag = false;
break;
}
x = 0;
} else {
if (ch == '-') {
flag = false;
break;
}
x = x * 10 + ch - '0';
}
}
if (flag) {
cout << "Yes!";
} else {
cout << "No!";
}
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}