zoukankan      html  css  js  c++  java
  • LightOJ

    链接:

    https://vjudge.net/problem/LightOJ-1354

    题意:

    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 same or not.

    思路:

    直接进制转换

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<math.h>
    #include<vector>
    #include<map>
    
    using namespace std;
    typedef long long LL;
    const int INF = 1e9;
    
    const int MAXN = 5e4+10;
    const int MOD = 1e9+7;
    
    bool Ok(int a, char *s)
    {
        int sum = 0;
        for (int i = 0;i < 8;i++)
        {
            if (s[i] == '0')
                continue;
            sum += 1<<(7-i);
        }
        return a == sum;
    }
    
    int main()
    {
        int t, cnt = 0;
        scanf("%d", &t);
        while(t--)
        {
            char s[100];
            int a, b, c, d;
            printf("Case %d:", ++cnt);
            scanf("%d.%d.%d.%d", &a, &b, &c, &d);
            scanf("%s", s);
            bool ok = true;
            if (!Ok(a, s))
                ok = false;
            if (!Ok(b, s+9))
                ok = false;
            if (!Ok(c, s+18))
                ok = false;
            if (!Ok(d, s+27))
                ok = false;
            if (ok)
                puts(" Yes");
            else
                puts(" No");
        }
    
        return 0;
    }
    
  • 相关阅读:
    JS 中 this 关键字详解
    Excel 文本函数
    Excel 日期和时间函数
    Excel引用和数学函数
    Excel-查找函数
    Excel-统计函数
    数据分析-业务知识
    Excel-逻辑函数
    Excel-基本操作
    电商数据分析总结
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11841460.html
Copyright © 2011-2022 走看看