HDU2206 IP的计算 【经典题】
IP的计算
可是粗心的我,经常将IP地址写错,如今须要你用程序来推断。
192.168.100.16
YES
合法的IP必然满足下面:
1、字符仅仅包括0-9和‘.’。
2、有且仅仅有3个‘.’;
3、每格数字最多3位且不超过255;
4、两个‘.’不能连在一起;
5、第一个字符不是‘.’.
#include <stdio.h>
char str[102];
int ok; int check(char ch){
if(ch >= '0' && ch <= '9') return 1;
if(ch == '.') return 2;
return 0;
} int main(){
int dot, dignum, a, dotsum;
while(gets(str)){
dotsum = a = dot = dignum = 0;
for(int i = 0; str[i]; ++i){
ok = check(str[i]);
if(!ok) break;
if(ok == 1){
dot = 0;
++dignum;
a = a * 10 + str[i] - '0';
if(dignum > 3 || a > 255){
ok = 0; break;
}
}else{
dignum = a = 0;
++dot; ++dotsum;
if(dot > 1 || dotsum > 3){
ok = 0; break;
}
}
}
if(str[0] == '.' || dot || dotsum != 3) ok = 0;
printf(ok ? "YES\n" : "NO\n");
}
return 0;
}
HDU2206 IP的计算 【经典题】的更多相关文章
- hdu 1251:统计难题(字典树,经典题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ 1811 Prime Test( Pollard-rho整数分解经典题 )
链接:传送门 题意:输入 n ,判断 n 是否为素数,如果是合数输出 n 的最素因子 思路:Pollard-rho经典题 /************************************** ...
- poj 1611:The Suspects(并查集,经典题)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21472 Accepted: 10393 De ...
- Hihicoder 题目1 : Trie树(字典树,经典题)
题目1 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编 ...
- poj 3264:Balanced Lineup(线段树,经典题)
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 32820 Accepted: 15447 ...
- poj 2503:Babelfish(字典树,经典题,字典翻译)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30816 Accepted: 13283 Descr ...
- poj 2001:Shortest Prefixes(字典树,经典题,求最短唯一前缀)
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12731 Accepted: 544 ...
- hdu 1247:Hat’s Words(字典树,经典题)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- jdk-tomcat环境变量设置
1.export命令直接在shell下设置 export JAVA_HOME=/home/yn4a/jdk1.6.0_16export PATH=$JAVA_HOME/bin:$PATHexport ...
- iOS ui界面vtf 开发
addConstraints 添加约束的步奏 添加控件到view中 设置translateResizeLayoutintoautolayout = false 添加约束 注意 约束 : 出现 有父子关 ...
- OC基础 内存管理
OC基础 内存管理 我们所了解的c语言内存管理,如下: (1)c语言的内存分配:char *p = (char*)malloc(100*sizeof(char)); (2)c语言的内存释放:free ...
- [.NET]Repeater控件使用技巧
1.控制Repeater表格中的按钮显隐 1.1 定义方法 public void Repeater1_ItemDataBinding(object sender, RepeaterItemEvent ...
- java鼠标与键盘事件监听
package cn.stat.p3.windowdemo; import java.awt.Button; import java.awt.FlowLayout; import java.awt.F ...
- StringBuilder 大量字符串时使用,速度比较快
public static void Main(string[] args) { Stopwatch sw = new Stopwatch(); //程序计时器 StringBuilder str = ...
- (原)python中matplotlib的颜色及线条控制
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6117528.html 参考网址: http://stackoverflow.com/questions ...
- OSG多屏显示问题
// testMultiScreen.cpp : Defines the entry point for the console application.// #include "stdaf ...
- PHP 汉字转拼音(首拼音,所有拼音)
<?php /** +------------------------------------------------------ * PHP 汉字转拼音 +------------------ ...
- kakfa-性能相关
1.增大partition最大连接数 kafka的集群有多个Broker服务器组成,每个类型的消息被定义为topic,同一topic内部的消息按照一定的key和算法被分区(partition)存储在不 ...