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 
  • 相关阅读:
    Redhat7.x静默安装19C客户端
    利用增量备份修复DG备库中的gap>>>>>>>>>>>有新增数据文件
    利用增量备份修复DG备库中的gap>>>>>>>>>>>无新增数据文件
    ORA-01665 control file is not a standby control file
    ORA-01110 ORA-01122 ORA-01110 ORA-01200解决办法
    Zabbix5.0+Grafana可视化部署教程
    RedHat 7.5配置bonding双网卡绑定(转)
    11.2.0.1 RAC环境部分磁盘组无法自动挂载,导致数据库实例无法启动(转)
    11.2.0.1 RAC环境经典bug CRS-4124: Oracle High Availability Services startup failed.
    Git配置SSH及常用命令
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2631351.html
Copyright © 2011-2022 走看看