Accepted solution

Virtual Judge IP Checking Solution

Open original problem
Source code

#include <iostream>

#include<stdio.h>

using namespace std;

int binary(int n)

{

     int temp = n,rem,binary=0,place = 1;

    while(temp > 0)

    {

        rem = temp % 2;

        binary = (rem * place) + binary;  /// convert to binary

        temp /= 2;

        place *= 10;

    }

    return binary;

}

int main()

{

    int T,test=0;

    cin>>T;

    while(T>0)

    {

        test++;

       long long int a, b, c, d,a1, b1, c1, d1;

        scanf("%lld.%lld.%lld.%lld",&a,&b,&c,&d);

        scanf("%lld.%lld.%lld.%lld",&a1,&b1,&c1,&d1);

        a = binary(a);

        b= binary(b);

        c = binary(c);

        d = binary(d);

        if(a==a1 && b==b1 && c==c1 && d==d1)

        {

            cout<<"Case "<<test<<": Yes"<<endl;

        }

        else

            cout<<"Case "<<test<<": No"<<endl;

       T--;

    }

    return 0;

}
Join the discussion

Add your comment