-
Notifications
You must be signed in to change notification settings - Fork 0
/
1354 - IP Checking.c
81 lines (79 loc) · 2.1 KB
/
1354 - IP Checking.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
int t,i,j,k,increment,ans,la,lb,c,n,p[4],q[4],o;
char a[37],b[37];
// freopen("in.txt","r",stdin);
scanf("%d",&t);
t++;
for( i = 1 ; i < t ; i++ )
{
scanf("%s %s",a,b);
la=strlen(a)-1;
lb=strlen(b)-1;
for( j = la,n=0,increment=1,c=0 ; j > -1 ; j-- )
{
if( a[j] == '.' || j == 0 ) //192.168.0.100
{ //11000000.10101000.00000000.11001000
if( j == 0 )
{
k=a[j]-48;
n+=k*increment;
p[c]=n;
}
else
p[c]=n;
n=0;
increment=1;
c++;
}
else
{
k=a[j]-48;
n+=k*increment;
increment*=10;
}
}
for( j = lb,increment=0,ans=0,c=0 ; j > -1 ; j-- )
{
if( b[j] == '.' || j == 0 ) //11000000.10101000.00000000.11001000
{
if( j == 0 )
{
o=b[j]-48;
if( o == 1 )
{
n=pow(2,increment);
ans+=n;
q[c]=ans;
}
else
q[c]=ans;
}
else
q[c]=ans;
ans=0;
increment=0;
c++;
}
else
{
o=b[j]-48;
if( o == 1 )
{
n=pow(2,increment);
ans+=n;
}
increment++;
}
}
if( p[0]==q[0] && p[1]==q[1] && p[2]==q[2] && p[3]==q[3])
printf("Case %d: Yes\n",i);
else
printf("Case %d: No\n",i);
}
return 0;
}