纯C:从后往前进行,依次分析,用了大量的分支语句,根据给的例子,不断完善所有的情况,超级笨的办法~~
#include <stdio.h>
#include <string.h>
#define SIZE 100
int main(void)
{
char ip[SIZE]={'\0'};
while(fgets(ip,SIZE,stdin))
{
int len=strlen(ip)-1;
int count=0;
int N=0;
int dian=0;//记录 点 的数目
for(int i=len-1;i>=0;i--)
{
if(ip[i] != '.')
{
count++;
}
else
{
if(ip[i+1]=='0' && (count==2 || count==3))
N=1;
if(count==0)
N=1;
count=0;
dian++;
}
if(i==0)
{
if(ip[i]=='0' && (count==2 || count==3))
N=1;
if(ip[i]=='.')
N=1;
}
if(count>3)
{
N=1;
}
else if(count>0 && count<3)
{
if(ip[i]>='0' && ip[i]<='9')
;
else
N=1;
}
else if(count==3)
{
if(ip[i]<='2')
{
if(ip[i]=='2')
{
if(ip[i+1]>'5')
N=1;
else if(ip[i+1]=='5')
{
if(ip[i+2]>'5')
N=1;
}
}
}
else
N=1;
}
}
if(N==1 || dian != 3)
printf("NO\n");
else
printf("YES\n");
dian=0;
}
return 0;
}