Home | Problems | Discuss | Login

  

求助啊!!!!!一直WA。。不知道哪里有错。。。

1103: IP判断

LightFar | 2011-03-08 15:24:56 | delete | edit
#include<stdio.h>
#include<stdlib.h>

int main()
{
  long iA,iB,iC,iD;
  char sB[101],cTemp;
  while(1)
  {
    if(scanf("%s",sB) == EOF) break;
    if((sscanf(sB,"%d.%d.%d.%d",&iA,&iB,&iC,&iD) == 4) && (sscanf(sB,"%*d.%*d.%*d.%*d%c",&cTemp) == 0))
    {
      if((iA>=0) && (iA<=255) && (iB>=0) && (iB<=255) && (iC>=0) && (iC<=255) && (iD>=0) && (iD<=255))
        printf("YES\n");
      else
        printf("NO\n");
    }
    else
    {
      printf("NO\n");
    }
  }
  //system("PAUSE");
}
 

Please login to reply.