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 
  • 相关阅读:
    Oracle删除.dbf文件报错
    Java 7 新的 try-with-resources 语句,自动资源释放
    模式对话框提交form之后总是打开新的页面
    MyEclipse更改项目的发布目录
    IntelliJ IDEA 更换发布目录
    java.sql.SQLException: ORA-00942: 表或视图不存在
    编码那点事
    配置nginx实现windows/iis应用负载均衡
    MSMQ消息队列
    .NET 分布式技术比较
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2631351.html
Copyright © 2011-2022 走看看