#include <stdio.h> int isIplegal(int ipNum,int ipBits); int main() { char ipAd[16]=""; int ipNum,ipBits,dotCount,isLegal; while(scanf("%s",ipAd)!=EOF){ ipNum=0,ipBits=0,dotCount=0,isLegal=1; if(ipAd[15]!='\0'||ipAd[8]=='\0')//ip长度不合法 { printf("No!\n"); continue; } for(int i=0;ipAd[i]!='\0';i++) { if(ipAd[i]<'0'||ipAd[i]>'9') { if(ipAd[i]=='.') { dotCount++; if(isIplegal(ipNum,ipBits)==0) { isLegal=0; break; } ipNum=ipBits=0; } else { isLegal=0; break; } } else if(ipAd[i]=='0') { ipBits++; if(ipAd[i+1]!='\0'&&ipAd[i+1]!='.'&&ipBits==1) { isLegal=0; break; } } else{ ipBits++; ipNum=ipNum*10+(ipAd[i]-'0'); } } if(dotCount!=3) isLegal=0; if(isIplegal(ipNum,ipBits)==0) isLegal=0; if(isLegal==0) printf("No!\n"); else printf("Yes!\n"); } return 0; } int isIplegal(int ipNum,int ipBits) { if(ipNum<0||ipNum>255||ipBits<0||ipBits>3) return 0; else return 1; }