Lightoj 1354 IP Checking

Problem link

আলোচনাঃ
lightoj 1354 IP Checking এই problem এ আমাকে একটা ip address এর decimal and binary form দুইটাই দেয়া আছে। আমাকে বলতে হবে ঐ ip address এর decimal and binary form একই ip address কে নির্দেশ করে কিনা?যদি same হয় তাহলে Yes আর না হলে No print করবো।

উত্তরঃ
তো আমরা একটা কাজ করতে পারি যে, decimal form টাকে binary তে convert করে দেখতে
পারি যে, given form এর সাথে মিলে কিনা। আবার binary form কে decimal এ convert করে
দেখতে পারি যে, given decimal form এর সাথে মিলে কিনা। এটা করলেই হবে।

তো আমি code এ binary form কে decimal এ convert করেছি। কিভাবে binary কে
decimal এ convert
করতে হয় তা নিচে চিত্রে দেখানো হলোঃ

Lightoj 1354 IP Checking image
Binary to Decimal conversion

You can also check this site.

এই problem এর input টা কিভাবে নিবো?

আমি যেহেতু binary কে decimal এ convert করেছি তাই binary কে string হিসেবে
নিয়েছি। এই problem এ cin দিয়ে string input নিই তাহলে প্রতিটা আলাদা string কে
কিভাবে চিনবো? সেটা করতে হলে অনেক কষ্ট করে manually করা লাগবে। কিন্তু এতো কষ্ট করার কি?

কারণ C++ এ getline() একটা function আছে। এই function এর parameter 3টা। 3 no টা optional. 3 no parameter নির্দেশ করে আমরা কোন character টা পেলে string input নেয়া off করে দিব। সাধারণত এই 3no parameter না দিলে getline() function টা ‘\n’ character পেলে input নেয়া off করে।

So, we can write for this problem=>

string s1;
getline (cin,s1,’.’)
যেহেতু আমরা ‘.’ পেলে একটা string variable এ input নেয়া
থামাতে চাই।

বিঃদ্রঃ এছাড়া empty string input নিতেও getline() function use করা হয়।

In this problem you have to use getline() to take input a empty string.

So, solve this. Thus you can know how to take input a empty string.

C++ Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=95+10;
#define pii pair<int,int>
#define MOD 10000007
#define PI acos(-1.0)
 
int check(string s)
{
    int num,ans=0;
    for(int i=s.size()-1,j=0;i>=0 && j<=s.size()-1;i--,j++){
        num=s[i]-'0';
        ans+=(pow(2,j)*num);
    }
    return ans;
}
 
int main()
{
    int t,cs=1,a,b,c,d;
    scanf("%d",&t);
 
    while(t--)
    {
        string s1,s2,s3,s4;
 
        scanf("%d.%d.%d.%d\n",&a,&b,&c,&d);
 
        getline(cin,s1,'.');
        getline(cin,s2,'.');
        getline(cin,s3,'.');
        getline(cin,s4,'\n');
 
        if(a==check(s1) && b==check(s2) && c==check(s3) && d==check(s4)){
            printf("Case %d: Yes\n",cs++);
        }
        else{
            printf("Case %d: No\n",cs++);
        }
 
    }
}

Related Problem : UVA – 673 – Parentheses Balance , Lightoj – 1006 – Hex-a-bonacci Solution

This Post Has 11 Comments

  1. bursa escort

    Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Kevyn Hieronymus Lipp

    1. tusher

      It’s difficult for me to understand your language.

  2. erotik

    There are no words to describe how bodacious this is. Nesta Curcio Vasiliu

    1. tusher

      Thanks.

  3. erotik

    Emer, you write so beautifully, drew me in completely, as always. Nina Humberto Daryl

    1. tusher

      Thanks:)

  4. Thank you, I have recently been looking for information about this topic for a long time and yours is the best I have came upon till now. But, what about the conclusion? Are you sure concerning the supply? Martina Tanney Sashenka

    1. tusher

      In the conclusion I discuss a issue of a different problem. I put that problem’s link above. Hope you understand now. Thanks for your reading.

    1. tusher

      Wow. Great to know that you share my site with your friends 😀

  5. Merryceact

    Don’t sit on cold ground: So a couple weeks ago, me and my friends were sitting on this cement kind of pedestal (as we called it) It’s basically the steps up to the portable. (classroom that no one uses) and this weird supply French teacher comes up to us and says: you shouldn’t be sitting on this ground, it’s too cold and it’s bad for your ovaries. I asked her how or why and she said that if children sit on cold ground their ovaries will freeze and that we won’t be able to have kids. Now it’s an inside joke between us about not sitting on cold ground[url=”https://hotroxuk.en-rabat.space”].[/url]

Leave a Reply