看见他计划


私信TA

用户名:hg59201

访问量:21330

签 名:

等  级
排  名 779
经  验 3600
参赛次数 0
文章发表 29
年  龄 0
在职情况 学生
学  校 河北工程大学
专  业

  自我简介:

#include<stdio.h>
#include<string.h>
int main()
{ char str[31];
  int s,i,j=0;
  int st[3];
  while(scanf("%s",&str)!=EOF)
  { s=strlen(str);
  if(str[0]!='1'&&str[0]!='2')//开头第一个不是1或2,结束
    {  printf("N\n");
      goto loop;
 }
 for(i=0;i<s;i++)
  { if((str[i]<48||str[i]>57)&&str[i]!='.')//输入中有任意一个不是点的字符,结束
     {
  printf("N\n");
          goto loop;
  }
  if(str[i]=='.')
   { st[j]=i;//记下三个点在数组的位置
      if(str[st[j]+1]=='0')每个点的下一位以零开头结束
       {
  printf("N\n");
          goto loop;
    }
     j++;
   }
  }
  if(st[0]>3)第一个点前的部分判断是不是在255间
   {  
   printf("N\n");
          goto loop;
   }
   else if(st[0]==3)
      { if((str[0]*100+str[1]*10+str[2])>255)
          {
    printf("N\n");
               goto loop;
    }
   }
  if(str[st[1]+1]==0||str[st[2]+1]==0)
   {  
   printf("N\n");
          goto loop;
     }
 if((st[1]-st[0]-1)>3)//间距大于三,说明是4位数,同上
  {
  printf("N\n");
          goto loop;
     } 
  else if((st[1]-st[0]-1)==3) 
       {if((str[st[0]+1]*100+str[st[0]+2]*10+str[st[0]+3])>255)
          {
    printf("N\n");
               goto loop;
    }
      }
  if((st[2]-st[1]-1)>3)同上
  {
  printf("N\n");
          goto loop;
     }      
  else if((st[2]-st[1]-1)==3) 
       {if((str[st[1]+1]*100+str[st[1]+2]*10+str[st[1]+3])>255)
          {
    printf("N\n");
               goto loop;
    }
      }
 printf("Y\n"); 
 loop: i=0;//做跳转的语句 
  }
 }



 

0.0分

2 人评分

  评论区