华为OJ2417合法
来源:互联网 发布:mysql的触发器 编辑:程序博客网 时间:2024/05/18 01:01
//华为oj合法IP题目
#include<iostream>
#include<string>
using namespace std;
bool IsDigit(char Digit)//判断字符是都为数字
{
bool flag = false;
if (Digit >= '0'&&Digit <= '9')
{
flag = true;
}
return flag;
}
bool IsFormatValid(char *IP)
{
int DotCnt = 0;
while (*IP != '\0')
{
if (*IP == '.')
{
DotCnt++;
}
else if (!IsDigit(*IP))
{
return false;
}
IP++;
}
if (DotCnt == 3)
return true;
else
return false;
}
bool IsValueVaild(char *IP)
{
int n = 0;
while (*IP != '\0')
{
if (IsDigit(*IP))
{
n = n * 10 + *IP-'0';
}
else
{
if (n > 255)
return false;
n = 0;
}
IP++;
}
return true;
}
int main()
{
char s[30];
//string s;
while (cin >> s)
{
if (IsFormatValid(s) && IsValueVaild(s))
{
cout << "YES" << endl;
}
else
cout << "NO" << endl;
}
return 0;
}
#include<iostream>
#include<string>
using namespace std;
bool IsDigit(char Digit)//判断字符是都为数字
{
bool flag = false;
if (Digit >= '0'&&Digit <= '9')
{
flag = true;
}
return flag;
}
bool IsFormatValid(char *IP)
{
int DotCnt = 0;
while (*IP != '\0')
{
if (*IP == '.')
{
DotCnt++;
}
else if (!IsDigit(*IP))
{
return false;
}
IP++;
}
if (DotCnt == 3)
return true;
else
return false;
}
bool IsValueVaild(char *IP)
{
int n = 0;
while (*IP != '\0')
{
if (IsDigit(*IP))
{
n = n * 10 + *IP-'0';
}
else
{
if (n > 255)
return false;
n = 0;
}
IP++;
}
return true;
}
int main()
{
char s[30];
//string s;
while (cin >> s)
{
if (IsFormatValid(s) && IsValueVaild(s))
{
cout << "YES" << endl;
}
else
cout << "NO" << endl;
}
return 0;
}
0 0
- 华为OJ2417合法
- 华为OJ ----合法IP
- 华为oj-合法IP
- 【华为oj】合法ip
- 华为oj 合法ip
- 华为oj 合法IP
- 【华为 OJ 】合法IP
- 【华为OJ】合法IP
- 华为OJ合法IP
- 华为oj之合法ip
- 华为OJ(合法IP)
- 【ACM】华为oj--合法ip
- 华为OJ合法IP判断
- 【华为OJ】【058-合法IP】
- 华为OJ 初级:合法IP
- 华为oj初级 合法IP
- 华为OJ--合法IP的判断
- 华为OJ基础篇-合法IP
- spymemcached和spring的整合
- Android冷启动优化
- Windows 下MySql无法实现远程访问。问题提示1024-can't get hostname for your address
- 通过透明度执行幻灯片
- Android实践 -- Android Wi-Fi 直连 传输数据
- 华为OJ2417合法
- SwipeRefreshLayout设置刷新圆圈距离顶部的距离
- html执行顺序的坑(附例子)
- 32位程序在64位系统下隐藏托盘图标
- listview源码解析
- 2016 年最受欢迎的编程语言是什么?
- 从零开始学C++之对象的使用(二):四种对象生存期和作用域、static 用法总结
- 御泥坊的购物车单选、全选,改变数量
- 用labview实现有趣字符串 图画