AcWing 3594. IP地址【处理字符串输入】
原题链接
简单
作者:
FrankieNCU
,
2023-05-08 16:58:38
,
所有人可见
,
阅读 122
sstream
#include <cstdio>
#include <iostream>
#include <sstream>
using namespace std;
string s, ts;
bool check(string ts) {
int res = 0;
for (int i = ts.size() - 1, r = 1; i >= 0; i--, r *= 10) res += r * ( ts[i] - '0' );
if ( res >= 0 && res <= 255 ) return true;
return false;
}
int main() {
while ( cin >> s ) {
stringstream ssin(s);
bool flag = false;
while ( getline(ssin, ts, '.') ) {
if ( ts[0] != '-' && check(ts) ) continue;
else {
flag = true;
break;
}
}
if ( flag ) puts("No!");
else puts("Yes!");
}
return 0;
}