LightOJ 1354 IP Checking Solution



 Problem Link: https://lightoj.com/problem/ip-checking

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int binaryToDecimal(int n)
{
    int num = n;
    int dec_value = 0;
    int base = 1;
    int temp = num;
    while (temp)
    {
        int last_digit = temp % 10;
        temp = temp / 10;
        dec_value += last_digit * base;
        base = base * 2;
    }
    return dec_value;
}
int main()
{
    int  n,t,i,k=1,a,b,a1,a2,b1,b2,c1,c2,d1,d2;
    char s[1];
    cin>>t;
    while(t--)
    {
        scanf("%d%c%d%c%d%c%d",&a1,&s,&b1,&s,&c1,&s,&d1);
        scanf("%d%c%d%c%d%c%d",&a2,&s,&b2,&s,&c2,&s,&d2);
        a2=binaryToDecimal(a2);
        b2=binaryToDecimal(b2);
        c2=binaryToDecimal(c2);
        d2=binaryToDecimal(d2);
        if(a1==a2&&b1==b2&&c1==c2&&d1==d2)
            printf("Case %d: Yes\n",k++);
        else
            printf("Case %d: No\n",k++);
    }
    return 0;
}



No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.