中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

512 做網(wǎng)站有做網(wǎng)站的嗎

512 做網(wǎng)站,有做網(wǎng)站的嗎,怎么做網(wǎng)頁簽到,福建漳州網(wǎng)站建設(shè)哪家便宜提示&#xff1a;文章 文章目錄 前言一、背景二、 2.1 2.2 總結(jié) 前言 接上文HJ39判斷兩個IP是否屬于同一子網(wǎng) 查了下&#xff0c;atoi可以轉(zhuǎn)換負(fù)數(shù)。 修改成下面的代碼 #include <stdio.h> #include <stdlib.h> #include <stdbool.h>bool isTargetSonN…

提示:文章

文章目錄

  • 前言
  • 一、背景
  • 二、
    • 2.1
    • 2.2
  • 總結(jié)

前言

接上文HJ39判斷兩個IP是否屬于同一子網(wǎng)


查了下,atoi可以轉(zhuǎn)換負(fù)數(shù)。

修改成下面的代碼

#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個輸出,很奇怪,我就調(diào)試。調(diào)試后我意識到goto會跳過其他scanf操作。
應(yīng)該先把數(shù)據(jù)采集完在處理。


總結(jié)

接下文:HJ39判斷兩個IP是否屬于同一子網(wǎng)(下)

http://m.risenshineclean.com/news/59264.html

相關(guān)文章:

  • 常見的企業(yè)網(wǎng)站有哪些百度店鋪怎么開通
  • 網(wǎng)站開發(fā) 實訓(xùn) 報告c++培訓(xùn)班學(xué)費一般多少
  • 河南最新任命12個廳級360優(yōu)化大師官方下載手機
  • 建設(shè)境外網(wǎng)站推廣軟文范文800字
  • 柳城網(wǎng)站建設(shè)官網(wǎng)優(yōu)化哪家專業(yè)
  • 做威客有什么靠譜網(wǎng)站2022最好的百度seo
  • 出口貿(mào)易網(wǎng)站廣告營銷的經(jīng)典案例
  • 網(wǎng)站建設(shè)的售后百度關(guān)鍵詞網(wǎng)站排名優(yōu)化軟件
  • 公司網(wǎng)站制作設(shè)上海網(wǎng)站制作公司
  • 網(wǎng)站開發(fā)畢設(shè)文獻(xiàn)網(wǎng)絡(luò)營銷swot分析
  • 網(wǎng)站后臺php開發(fā)教程seo手機關(guān)鍵詞排行推廣
  • 網(wǎng)站 分析最新戰(zhàn)爭新聞事件今天
  • 第三方做的網(wǎng)站不給源代碼站長工具如何使用
  • html怎么做網(wǎng)站設(shè)計以網(wǎng)絡(luò)營銷為主題的論文
  • 做淘寶客網(wǎng)站教程短網(wǎng)址生成網(wǎng)站
  • 建湖營銷型網(wǎng)站建設(shè)工作室銀川網(wǎng)站seo
  • 錦州網(wǎng)站建設(shè)品牌seo優(yōu)化需要多少錢
  • 個人網(wǎng)站制作網(wǎng)站2022國內(nèi)外重大新聞事件10條
  • 山東青島網(wǎng)站建設(shè)公司哪家專業(yè)制作網(wǎng)頁的流程步驟
  • 長寧網(wǎng)站推廣公司網(wǎng)絡(luò)推廣渠道公司
  • 學(xué)做衣服網(wǎng) 繽紛網(wǎng)站查收錄網(wǎng)站
  • 江陰建設(shè)銀行網(wǎng)站全網(wǎng)自媒體平臺大全
  • 網(wǎng)站建設(shè)相關(guān)推薦網(wǎng)絡(luò)優(yōu)化工程師前景
  • 做網(wǎng)站聽的純音樂seo關(guān)鍵詞首頁排名代發(fā)
  • 網(wǎng)站開發(fā)工具 楓子科技谷歌代運營
  • 怎么制作網(wǎng)站seo公司優(yōu)化方案
  • wordpress自定義樣式什么是seo文章
  • 東莞手機網(wǎng)站制作公司鄭州網(wǎng)站顧問
  • 網(wǎng)站圖片怎么做緩存網(wǎng)店培訓(xùn)騙局
  • 金融行業(yè)網(wǎng)站制作天津百度推廣公司