Convert decimal to binary or binary to decimal
///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
ll tst,ca=1;
cin>>tst;
while(tst--)
{
int arr[10],arr1[10],num=0,num1=0,k=0,k1=0,flag=0;
string str,str1;
cin>>str>>str1;
str.append(".");
str1.append(".");
for(ll i=0;i<str.size();i++)
{
if(str[i]=='.') arr[k++]=num,num=0;
else num=(num*10)+(str[i]-48);
}
for(ll i=0;i<str1.size();i++)
{
if(str1[i]=='.') arr1[k1++]=num1,num1=0;
else num1=(num1*10)+(str1[i]-48);
}
for(ll i=0;i<k;i++)
{
ll base=1,decimal=0;
num=arr1[i];
while(num!=0)
{
decimal+=(num%10)*base;
num/=10;
base*=2;
}
if(arr[i]!=decimal) flag=1;
}
printf("Case %lld: ",ca++);
if(flag) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
return 0;
}
///Alhamdulillah
problem link:https://lightoj.com/problem/ip-checking
Comments
Post a Comment