zoukankan      html  css  js  c++  java
  • 1354

    1354 - IP Checking
    Time Limit: 2 second(s) Memory Limit: 32 MB

    An IP address is a 32 bit address formatted in the following way

    a.b.c.d

    where a, b, c, d are integers each ranging from 0 to 255. Now you are given two IP addresses, first one in decimal form and second one in binary form, your task is to find if they are same or not.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with two lines. First line contains an IP address in decimal form, and second line contains an IP address in binary form. In binary form, each of the four parts contains 8 digits. Assume that the given addresses are valid.

    Output

    For each case, print the case number and "Yes" if they are same, otherwise print "No".

    Sample Input

    Output for Sample Input

    2

    192.168.0.100

    11000000.10101000.00000000.11001000

    65.254.63.122

    01000001.11111110.00111111.01111010

    Case 1: No

    Case 2: Yes

    题解:写一下就过了

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #define mem(x,y) memset(x,y,sizeof(x))
     7 using namespace std;
     8 const int INF=0x3f3f3f3f;
     9 char s1[100],s2[100];
    10 int main(){
    11     int T,cnt=0,l1,l2;
    12     int a[5],b[5];
    13     scanf("%d",&T);
    14     while(T--){
    15         scanf("%s%s",s1,s2);
    16         l1=strlen(s1);l2=strlen(s2);
    17         int temp=0,k=0;
    18         for(int i=0;i<l1;i++){
    19             if(s1[i]=='.')a[k++]=temp,temp=0;
    20             else temp=temp*10+s1[i]-'0';
    21         }
    22         a[k++]=temp;
    23         temp=0;k=0;
    24         for(int i=0;i<l2;i++){
    25             if(s2[i]=='.')b[k++]=temp,temp=0;
    26             else temp=temp*2+s2[i]-'0';
    27         }
    28         b[k++]=temp;
    29         int flot=1;
    30         for(int i=0;i<4;i++){
    31             if(a[i]!=b[i])flot=0;
    32         }
    33         if(flot)printf("Case %d: Yes
    ",++cnt);
    34         else printf("Case %d: No
    ",++cnt);
    35     }
    36     return 0;
    37 }
  • 相关阅读:
    简体繁体互译代码段:
    require.js使用baseUrl + paths导入文件配置的3种方法
    vue + vue-router + vue-resource 基于vue-cli脚手架 --->笔记
    解决webstorm卡顿问题
    js 函数闭包内部返回函数体调用方法难点解答
    java学习笔记之位运算符
    java集合类学习笔记之LinkList
    java集合类学习笔记之ArrayList
    java学习笔记之对象序列化
    springboot集成巨杉数据库
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4947259.html
Copyright © 2011-2022 走看看