当前位置: 首页 > news >正文

谷歌可以做网站吗佛山做网站建设

谷歌可以做网站吗,佛山做网站建设,做旅游网站的目的与意义,php网站建设公司提示&#xff1a;文章 文章目录 前言一、背景二、 2.1 2.2 总结 前言 接上文HJ39判断两个IP是否属于同一子网 查了下&#xff0c;atoi可以转换负数。 修改成下面的代码 #include <stdio.h> #include <stdlib.h> #include <stdbool.h>bool isTargetSonN…

提示:文章

文章目录

  • 前言
  • 一、背景
  • 二、
    • 2.1
    • 2.2
  • 总结

前言

接上文HJ39判断两个IP是否属于同一子网


查了下,atoi可以转换负数。

修改成下面的代码

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>bool isTargetSonNet(int array[], int len)
{int tempArray[32] = {0};int tempArrayIndex = 0;for(int i = 0; i < len; i++){int data = array[i];if(data > 255 || data < 0){return false;}int index = ((tempArrayIndex + 1) * 8);while(data){int dat = data % 2;tempArray[--index] = dat;data /= 2;}tempArrayIndex++;}int count = 0;for(int i = 0; i + 1 < 32; i++){int temp = tempArray[i] - tempArray[i + 1];if(temp != 0 && temp != 1){return false;}if(temp == 1){count++;}}if(count != 1){return false;}return true;
}int main() {int a, b;char sonNet[20] = {'\0'};char ip1[20] = {'\0'};char ip2[20] = {'\0'};int arraySonNet[4] = {0};int arrayIp1[4] = {0};int arrayIp2[4] = {0};while (scanf("%s", sonNet) != EOF) { // 注意 while 处理多个 case// 64 位输出请用 printf("%lld") to char output = 'f';char delimiters[2] = ".";char* p = strtok(sonNet, delimiters);int index = 0;while(p != NULL){//printf("%s\n", p);int data = atoi(p);// if(data > 255)// {//     output = '1';//     break;// }// else if(data != 255 && data != 0)// {//     output = '1';//     break;// }arraySonNet[index++] = data;p = strtok(NULL, delimiters);}if(!isTargetSonNet(arraySonNet, 4)){output = '1';}if(output != 'f'){printf("%c\n", output);break;}if(scanf("%s", ip1) != EOF){p = strtok(ip1, delimiters);int index = 0;while(p != NULL){//printf("%s\n", p);int data = atoi(p);if(data > 255 || data < 0){output = '1';break;}arrayIp1[index++] = data;p = strtok(NULL, delimiters);}}if(output != 'f'){printf("%c\n", output);break;}if(scanf("%s", ip2) != EOF){p = strtok(ip2, delimiters);int index = 0;while(p != NULL){//printf("%s\n", p);int data = atoi(p);if(data > 255 || data < 0){output = '1';break;}arrayIp2[index++] = data;p = strtok(NULL, delimiters);}}if(output != 'f'){printf("%c\n", output);break;}int count = 0;for(int i = 0; i < 4; i++){if( (ip1[i] & sonNet[i]) == (ip2[i] & sonNet[i]) ){++count;}}if(output == 'f'){if(count == 4){output = '0';}else {output = '2';}}printf("%c\n", output);}return 0;
}

验证一下demo示例

示例有错误

255.255.255.0
192.168.224.256
192.168.10.4
255.0.0.0
193.194.202.15
232.43.7.59
255.255.255.0
192.168.0.254
192.168.0.1

输出 1

修改成下面的代码也不行

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>bool isTargetSonNet(int array[], int len)
{int tempArray[32] = {0};int tempArrayIndex = 0;for(int i = 0; i < len; i++){int data = array[i];if(data > 255 || data < 0){return false;}int index = ((tempArrayIndex + 1) * 8);while(data){int dat = data % 2;tempArray[--index] = dat;data /= 2;}tempArrayIndex++;}int count = 0;for(int i = 0; i + 1 < 32; i++){int temp = tempArray[i] - tempArray[i + 1];if(temp != 0 && temp != 1){return false;}if(temp == 1){count++;}}if(count != 1){return false;}return true;
}int main() {int a, b;char sonNet[20] = {'\0'};char ip1[20] = {'\0'};char ip2[20] = {'\0'};int arraySonNet[4] = {0};int arrayIp1[4] = {0};int arrayIp2[4] = {0};while (scanf("%s", sonNet) != EOF) { // 注意 while 处理多个 case// 64 位输出请用 printf("%lld") to char output = 'f';char delimiters[2] = ".";char* p = strtok(sonNet, delimiters);int index = 0;while(p != NULL){//printf("%s\n", p);int data = atoi(p);// if(data > 255)// {//     output = '1';//     break;// }// else if(data != 255 && data != 0)// {//     output = '1';//     break;// }arraySonNet[index++] = data;p = strtok(NULL, delimiters);}if(!isTargetSonNet(arraySonNet, 4)){output = '1';}if(output != 'f'){printf("%c\n", output);break;}if(scanf("%s", ip1) != EOF){p = strtok(ip1, delimiters);int index = 0;while(p != NULL){//printf("%s\n", p);int data = atoi(p);if(data > 255 || data < 0){output = '1';break;}arrayIp1[index++] = data;p = strtok(NULL, delimiters);}}if(output != 'f'){printf("%c\n", output);continue;}if(scanf("%s", ip2) != EOF){p = strtok(ip2, delimiters);int index = 0;while(p != NULL){//printf("%s\n", p);int data = atoi(p);if(data > 255 || data < 0){output = '1';break;}arrayIp2[index++] = data;p = strtok(NULL, delimiters);}}if(output != 'f'){printf("%c\n", output);continue;}int count = 0;for(int i = 0; i < 4; i++){if( (ip1[i] & sonNet[i]) == (ip2[i] & sonNet[i]) ){++count;}}if(output == 'f'){if(count == 4){output = '0';}else {output = '2';}}printf("%c\n", output);}return 0;
}

示例有错误

255.255.255.0
192.168.224.256
192.168.10.4
255.0.0.0
193.194.202.15
232.43.7.59
255.255.255.0
192.168.0.254
192.168.0.1

输出

1
1
2
0

修改代码,修改成goto,但是还是不行,会打印4个输出,很奇怪,我就调试。调试后我意识到goto会跳过其他scanf操作。
应该先把数据采集完在处理。


总结

接下文:HJ39判断两个IP是否属于同一子网(下)

http://www.mmbaike.com/news/56601.html

相关文章:

  • 邢台营销型网站建设费用长沙做网站推广公司咨询
  • 手機如何做网站今日头条重大消息
  • 邢台市防疫办电话是多少网站seo价格
  • 菏泽北京网站建设百度推广开户费用
  • 人人秀h5制作软件下载惠州市seo广告优化营销工具
  • 做软件营销网站怎么样网络黄页推广软件哪个好
  • 网站建建设公司和网络自建成都有实力的seo团队
  • 德国域名申请网站网络营销课程培训课程
  • 个人网站主页制作网站免费
  • 长沙找人做网站市场调研的方法有哪些
  • 用明星名字做网站国内哪个搜索引擎最好用
  • 做网站哪个公司好好的竞价推广托管
  • 惠州企业网站建设选哪家百度关键词的费用是多少
  • 做网站怎么做多少钱株洲网站建设
  • 网站用哪个软件做上海企业seo
  • 网站的建设和品牌价值的关系sem和seo的关系
  • 用php做网站需要什么北京互联网营销公司
  • 南京市公共建设中心网站手机优化游戏性能的软件
  • 微网站如何做宣传产品策划方案怎么做
  • 网站做微信支付接口2345网址导航设置
  • 廊坊建设局网站6软件推广赚钱
  • 中山企业手机网站建设最有效的线上推广方式
  • 安装Wordpress个人网站2024年3月新冠高峰
  • 免费ppt模版网站企业网站模板图片
  • 2019年新电商法做网站优化大师好用吗
  • 石家庄网站建设哪家便宜搜外
  • 个人如何申请网站2021年关键词有哪些
  • wordpress 外网班级优化大师免费下载电脑版
  • 上海有哪几家做新房的网站怎么做网站排名
  • 企业形象设计论文2000字惠州seo快速排名