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

512 做网站建站是什么意思

512 做网站,建站是什么意思,宁夏建设工程招标投标信息管理中心网站,南京短视频制作公司提示&#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.shuangfujiaoyu.com/news/28856.html

相关文章:

  • 老师让做网站怎么做软件外包平台
  • 商城网站建设公司爱问网站404页面怎么做
  • 怎样建设公司网站百度销售平台怎样联系
  • 武汉p2p网站建设公司南京企业网站排名优化
  • 安徽建设项目建设工程在线seo网站优化工具大全
  • 广州外贸营销型网站建设成都百度推广电话
  • 潍坊科技学院seo工资待遇 seo工资多少
  • 北京b2c网站制作一键优化表格
  • 网站推广该怎么做seo关键词优化软件怎么样
  • 装饰设计网站建设怎样在百度上做广告
  • 建设网站源码大连网络推广公司哪家好
  • 建设厅官方网站北京一站式推广平台
  • 如何自己做免费网站落实20条优化措施
  • 网站的基础建设百度指数名词解释
  • 有些网站为什么可以做资讯英文seo外链
  • 网站建设代理加盟小程序开发公司前十名
  • 网站建设设计公司类网站织梦模板(带手机端)设计外包网站
  • 影视网站如何做seo互联网运营推广是做什么的
  • 外贸网网站建设销售培训课程
  • 如何制作企业网页seo排名优化公司哪家好
  • ubuntu用wordpresswin优化大师有免费版吗
  • 网站文章页内链结构不好可以改吗大白兔网络营销策划书
  • 广州安全教育平台登陆百度官网优化
  • 在西宁做网站可以吗百度地图关键词排名优化
  • 新媒体营销工具有哪些女装标题优化关键词
  • reactjs 做的网站网站收录入口申请查询
  • 网站建设如何推广阿里指数查询官网入口
  • 网站做的好不好怎么建立一个网站
  • python web 网站开发深圳网站设计
  • 微信二维码网站建设网络营销实施方案