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 }
  • 相关阅读:
    九九乘法表
    数据汇总特殊处理-标题都在第N行
    Python库——Faker 安装及用法
    faker库 生成数据导入文件
    faker库的使用 faker是一个第三方Python包,为您生成你所需要的任何(假)数据。 安装:pip install faker
    生成随机数据:faker库
    运算符
    初识编码
    网页设计基础(二)
    网页设计基础
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4947259.html
Copyright © 2011-2022 走看看