int _to_int(char * str, int start_idx, int end_idx)
{
int a = 0, i;
for (i = start_idx; i <= end_idx; ++i)
{
a = a * 10 + (str[i] - '0');
}
return a;
}
/*
* 将ip字符串转化为4字节的整形
*/
int ip_to_int(char * ip)
{
int start = 0, i = 0, ret = 0;
int shift_factor = 3; // 一开始要向右移动3 * 8位
char c;
while (c = ip[i])
{
if (c == '.')
{
int a = _to_int(ip, start, i - 1);
int temp = shift_factor * 8;
ret = ret | (a << temp);
shift_factor--;
start = i + 1;
}
i++;
}
return ret;
}
#include <stdio.h>
int main()
{
char a1[15], a2[15], a3[15];
gets(a1);
gets(a2);
gets(a3);
int ip1 = ip_to_int(a1);
int ip2 = ip_to_int(a2);
int ip3 = ip_to_int(a3);
int result = 0;
if ((ip1 & ip3) == (ip2 & ip3))
{
result = 1;
}
printf("%d", result);
return 0;
}
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef struct ip
{
int first;
int second;
int three;
} IP;
int judgeIp(string ipSubNet,IP &ip)
{
int index=0;
ip.first=atoi(&ipSubNet[index]);
if(ip.first>255)
return 0;
index++;
index=ipSubNet.find_first_of('.',index);
ip.second=atoi(&ipSubNet[++index]);
if(ip.second>255)
return 0;
index++;
index=ipSubNet.find_first_of('.',index);
ip.three=atoi(&ipSubNet[++index]);
if(ip.three>255)
return 0;
index++;
index=ipSubNet.find_first_of('.',index);
ip.fouth=atoi(&ipSubNet[++index]);
if(ip.fouth>255)
return 0;
return 1;
}
int main()
{
string ipSubNet,ipAdd1,ipAdd2;
IP subNet,ip1,ip2;
while(cin>>ipSubNet>>ipAdd1>>ipAdd2)
{
if(judgeIp(ipSubNet,subNet)&&judgeIp(ipAdd1,ip1)&&judgeIp(ipAdd2,ip2))
{
ip1.first=ip1.first & subNet.first;
ip1.second=ip1.first & subNet.second;
ip1.second=ip1.first & subNet.second;
ip1.fouth=ip1.first & subNet.fouth;
ip2.first=ip2.first & subNet.first;
ip2.second=ip2.first & subNet.second;
ip2.second=ip2.first & subNet.second;
ip2.fouth=ip2.first & subNet.fouth;
if(ip1.first==ip2.first&&ip1.second==ip2.second&&ip1.three==ip2.three&&ip1.fouth==ip2.fouth)
cout<<'0'<<endl;
else
cout<<'2'<<endl;
}
else
cout<<'1'<<endl;
}
return 0;
}
ip_addr.h
#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
(mask)->addr) == \
((addr2)->addr & \
(mask)->addr))
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有