【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 

 

转载于:https://www.cnblogs.com/ismdeep/archive/2012/08/10/2631351.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值