O - IP Checking

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 the 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

InputcopyOutputcopy
2
192.168.0.100
11000000.10101000.00000000.11001000
65.254.63.122
01000001.11111110.00111111.01111010
Case 1: No
Case 2: Yes 
模拟即可 
#include<bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define int i64
#define endl '\n'
int n,m,sum,ans,A,B;
/*
*/
void solve()
{
    int t;
    cin >> t;
    for(int i = 1;i <= t;i++)
    {
        bool is = true;
        string str;
        char ch;
        string ans1 = "";
        vector<int>v;
        vector<string>s;
        cin >> str;
        std::stringstream s2(str);
        while (getline(s2, str, '.'))
        v.push_back(stoi(str));
        
        cin >> str;
        std::stringstream ss(str);
        while (getline(ss, str, '.'))
        s.push_back(str);
        for(int i = 0;i < 4;i++)
        {
            string s3 =  bitset<32>(v[i]).to_string();
            s3 = s3.substr(24,8);
            if(s[i] != s3)
            {is = false;break;} 
        }

        is ? ans1 = "Yes" : ans1 = "No";
        cout << "Case "<< i << ": " <<  ans1 << endl;   
    }
}

signed main()
{
   // cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    //cin >> T;
    while(T--)
    solve();
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值