#include<bits/stdc++.h>
using namespace std;
bool func1(string str){
if(str[0] == '0' && str.size() > 1){
return false;
}
return true;
}
bool judge(string str){
vector<string> address;
int len = str.size();
int beginpos = 0;
for(int i = 0; i <= len; i++){
if(str[i] == '.' || i == len){
address.push_back(str.substr(beginpos, i - beginpos));
beginpos = i + 1;
}
}
if(address.size() != 4){
return false;
}
for(int i = 0; i < 4; i++){
if(!func1(address[i])){
return false;
}
}
for(int i = 0; i < 4; i++){
if(stoi(address[i]) < 0 || stoi(address[i]) > 255){
return false;
}
}
return true;
}
int main(){
string str;
while(cin >> str){
if(judge(str)){
cout << "Yes!" << endl;
}
else{
cout << "No!" << endl;
}
}
return 0;
}
视作字符串处理

京公网安备 11010502036488号