解题思路:
(1)判断范围
#include<iostream>
#include<vector>
using namespace std;
void helper(string &s) {
vector<int> v;
int i=0;
string str="";
while(i<s.length()) {
if(s[i]!='.') {
while(s[i]!='.') {
str+=s[i];
i++;
}
v.push_back(stoi(str));
str="";
} else {
i++;
}
}
for(int i=0;i<v.size();i++) {
if(v[i]>255 || v[i]<0) {
cout<<"NO"<<endl;
return;
}
}
cout<<"YES"<<endl;
return;
}
int main() {
string s;
while(cin>>s) {
helper(s);
}
return 0;
}