zoukankan      html  css  js  c++  java
  • 【lightoj 1354 IP Checking 来来,,发个巨水的题目玩玩。】

    1354 - IP Checking
    Time Limit: 2 second(s) Memory Limit: 32 MB

    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.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with two lines. First line contains an IP address in decimal form, and second line contains an IP address in binary form. In binary form, each of the four parts contains 8 digits. Assume that the given addresses are valid.

    Output

    For each case, print the case number and "Yes" if they are same, otherwise print "No".

    Sample Input

    Output for Sample Input

    2

    192.168.0.100

    11000000.10101000.00000000.11001000

    65.254.63.122

    01000001.11111110.00111111.01111010

    Case 1: No

    Case 2: Yes


    PROBLEM SETTER: JANE ALAM JAN
     
     
     
     
     
     
      1 // Project name : 1354 ( IP Checking ) 
      2 // File name    : main.cpp
      3 // Author       : iCoding
      4 // E-mail       : honi.linux@gmail.com
      5 // Date & Time  : Fri Aug 10 10:01:30 2012
      6 
      7 
      8 #include <iostream>
      9 #include <stdio.h>
     10 #include <string>
     11 #include <cmath>
     12 #include <algorithm>
     13 using namespace std;
     14 
     15 /*************************************************************************************/
     16 /* data */
     17 
     18 int a, b, c, d;
     19 bool iFlag;
     20 string ip;
     21 int tmp;
     22 /*************************************************************************************/
     23 /* procedure */
     24 
     25 void iInit()
     26 {
     27     scanf("%d.%d.%d.%d", &a, &b, &c, &d);
     28     //printf("%d %d %d %d \n", a, b, c, d);
     29     cin >> ip;
     30     iFlag = true;
     31 }
     32 
     33 void iShow(int a, int b)
     34 {
     35     cout << a << " " << b << endl;
     36 }
     37 
     38 bool iIsEqual()
     39 {
     40     tmp = 0;
     41     int iIndex = 0;
     42     while (ip[iIndex] != '.')
     43     {
     44         tmp *= 2;
     45         tmp += (ip[iIndex] - '0');
     46         iIndex++;
     47     }
     48     if (tmp != a)
     49     {
     50         iFlag = false;
     51     }
     52 
     53     tmp = 0;
     54     iIndex++;
     55     while (ip[iIndex] != '.')
     56     {
     57         tmp *= 2;
     58         tmp += (ip[iIndex] - '0');
     59         iIndex++;
     60     }
     61     //iShow(tmp,b);
     62     if (tmp != b)
     63     {
     64         iFlag = false;
     65     }
     66 
     67     tmp = 0;
     68     iIndex++;
     69     while (ip[iIndex] != '.')
     70     {
     71         tmp *= 2;
     72         tmp += (ip[iIndex] - '0');
     73         iIndex++;
     74     }
     75     if (tmp != c)
     76     {
     77         iFlag = false;
     78     }
     79 
     80 
     81     tmp = 0;
     82     iIndex++;
     83     while (ip[iIndex] != '\0')
     84     {
     85         tmp *= 2;
     86         tmp += (ip[iIndex] - '0');
     87         iIndex++;
     88     }
     89     if (tmp != d)
     90     {
     91         iFlag = false;
     92     }
     93 
     94 
     95     return iFlag;
     96 }
     97 
     98 /*************************************************************************************/
     99 /* main */
    100 int main()
    101 {
    102     int iT;
    103     scanf("%d", &iT);
    104     for (int  iCaseCount = 1; iCaseCount <= iT; iCaseCount++)
    105     {
    106         printf("Case %d: ", iCaseCount);
    107 
    108         iInit();
    109 
    110         if (iIsEqual())
    111         {
    112             printf("Yes\n");
    113         }
    114         else
    115         {
    116             printf("No\n");
    117         }
    118     }
    119     return 0;
    120 }
    121 
    122 // end 
    123 // Code by Sublime text 2
    124 // iCoding@CodeLab 
  • 相关阅读:
    [算法练习]ZigZag Conversion
    获取所有后缀DDE打开命令
    [算法练习]Add Two Numbers
    获取dll编译时生成的pdb文件的名称
    [转载]定位 C++/CLI 库的加载失败异常
    在C++/CLI环境下,千万不要把普通全局函数当标准C/C++的函数指针传递给native的库使用
    Mono集成中使用api获取当前mono 调用堆栈的方法
    简单对比了一下MonoXml与SystemXml在Unity下的表现
    C++从LPEXCEPTION_POINTERS获取调用堆栈
    遇到doxygen生成的chm文档目录如果有中文是乱码?
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2631351.html
Copyright © 2011-2022 走看看