-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path合法IP.cpp
57 lines (50 loc) · 810 Bytes
/
合法IP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
using namespace std;
void Solution(char* str)
{
if (str == NULL) return;
int count = 0, i = 0;
char *p = str;
for (int i = 0; i < strlen(str); i++)
if (str[i] == '.' && str[i + 1] != '.')
count++;
char *p2 = str;
if (count == 3)
{
int k = 0, temp = 0, flag = 0;
for (int j = 0; j < 4; j++)
{
while (*p2 != '.' && *p2 != '\0')
{
if (*p2 >= '0' && *p2 <= '9')
{
temp = temp * 10 + *p2 - '0';
}
//else
//{
// cout << "NO1" << endl;
// break;
//}
++p2;
}
if (temp < 0 || temp > 255)
{
cout << "NO" << endl;
break;
}
else
flag++;
temp = 0; ++p2;
}
if (flag == 4)
cout << "YES" << endl;
}
else
cout << "NO" << endl;
}
void main()
{
char str[500];
cin >> str;
Solution(str);
}