Newguy


私信TA

用户名:772007765

访问量:82078

签 名:

已秃人士

等  级
排  名 28
经  验 14591
参赛次数 3
文章发表 92
年  龄 0
在职情况 在职
学  校
专  业

  自我简介:

解题思路

#include <stdio.h>
#include <stdlib.h>   //用atoi()把字符串中的数字转换成int类型的
#include <string.h>   //用strcmp()来与"End of file"比较;用strchr()寻找最后一个.的位置
void main()
{
	char IP[31];
	int cheak,i;     //cheak用来判断字符串是否符合条件
	char *str;      //声明一个指针来指向.的地址

	while (gets(IP)!=NULL&&strcmp(IP,"End of file"))
	{
		for (i=1;i<=4;i++)
		{
			if (i!=4)                         
			{
				str=strchr( IP ,'.' );    //str指向最后一个.的地址
				cheak=atoi(str+1);        //(str+1)指向.后面的字符,如果不是数字cheak=0
				if (cheak&&cheak>=0&&cheak<=255)
					*str=' ';         //把.更换成' ',让下一次循环指向上一个.
				else
				{
					puts("N");
					break;
				}
			}
			else                             //当i等于4时首字符没有'.'直接检查
			{
				cheak=atoi(IP);
				if (cheak&&cheak>=0&&cheak<=255)
					puts("Y");
				else
					puts("N");
			}
		}
	}
}

:
倒叙检查字符串  1.2.3.b   从b开始,再到3,再到2,再到1    




注意事项:





参考代码:

 

0.0分

0 人评分

  评论区

为什么不是先检查2,然后是3,然后是b,最后是1呢?strchr是返回第一个‘ . ’的地址吧,不是吗?
2019-01-30 11:21:58
  • «
  • 1
  • »