lightoj-1354 - IP Checking(水题)

1354 - IP Checking
PDF (English) Statistics Forum
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

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5
 6 int main(){
 7
 8     int T,a[4],a1[4];
 9
10     scanf("%d",&T);
11     for(int t=1;t<=T;t++){
12
13         scanf("%d.%d.%d.%d",&a[0],&a[1],&a[2],&a[3]);
14         scanf("%d.%d.%d.%d",&a1[0],&a1[1],&a1[2],&a1[3]);
15         int flag = 0;
16         for(int j=0;j<4&&flag==0;j++)
17             for(int i=0;i<8;i++){
18                 if((a[j]&1)!=a1[j]%10){
19                     flag = 1;
20                     break;
21                 }
22                 a[j]/=2,a1[j]/=10;
23             }
24
25         printf("Case %d: ",t);
26         printf(flag==0?"Yes\n":"No\n");
27     }
28
29     return 0;
30 }
31 //未优化
32 //int main(){
33 //
34 //    int T,a,b,c,d,a1,b1,c1,d1;
35 //
36 //    scanf("%d",&T);
37 //    for(int t=1;t<=T;t++){
38 //
39 //        scanf("%d.%d.%d.%d",&a,&b,&c,&d);
40 //        scanf("%d.%d.%d.%d",&a1,&b1,&c1,&d1);
41 //        int flag = 0;
42 //
43 //        for(int i=0;i<8;i++){
44 //            if((a&1)!=a1%10){
45 //                flag = 1;
46 //                break;
47 //            }
48 //            a/=2,a1/=10;
49 //        }
50 //        if(flag==0){
51 //            for(int i=0;i<8;i++){
52 //                if((b&1)!=b1%10){
53 //                    flag = 1;
54 //                    break;
55 //                }
56 //                b/=2,b1/=10;
57 //            }
58 //        }
59 //        if(flag==0){
60 //            for(int i=0;i<8;i++){
61 //                if((c&1)!=c1%10){
62 //                    flag = 1;
63 //                    break;
64 //                }
65 //                c/=2,c1/=10;
66 //            }
67 //        }
68 //        if(flag==0){
69 //            for(int i=0;i<8;i++){
70 //                if((d&1)!=d1%10){
71 //                    flag = 1;
72 //                    break;
73 //                }
74 //                d/=2,d1/=10;
75 //            }
76 //        }
77 //        printf("Case %d: ",t);
78 //        printf(flag==0?"Yes\n":"No\n");
79 //    }
80 //
81 //    return 0;
82 //} 
时间: 2024-08-07 09:03:27

lightoj-1354 - IP Checking(水题)的相关文章

LightOJ - 1354 IP Checking

IP Checking Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Submit Status Description 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

LightOJ 1109 -1354 - IP Checking(字符串的处理)

题目大意: 这题的意思就是说,给两个字符串,一个字符串中的数字是用10进制表示的,一个字符串的数字是用2进制表示的,看看十进制和二进制是否对应. 解题思路: 处理在'.'上.... 代码: 1 # include<cstdio> 2 # include<iostream> 3 # include<cstring> 4 # include<cmath> 5 6 using namespace std; 7 8 # define MAX 50 9 10 char

LightOJ 1166 Old Sorting 置换群 或 贪心 水题

LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : 2017-07-20 14:45:30 * @FileName: LightOJ 1166 贪心 或 置换群 水题.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.co

Lightoj 1112 - Curious Robin Hood 【单点改动 + 单点、 区间查询】【树状数组 水题】

1112 - Curious Robin Hood PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 64 MB Robin Hood likes to loot rich people since he helps the poor people with this money. Instead of keeping all the money together he does another trick.

Lightoj 1112 - Curious Robin Hood 【单点修改 + 单点、 区间查询】【树状数组 水题】

1112 - Curious Robin Hood PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 64 MB Robin Hood likes to loot rich people since he helps the poor people with this money. Instead of keeping all the money together he does another trick.

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

HDU 1800 Flying to the Mars (水题)

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11099    Accepted Submission(s): 3572 Problem Description In the year 8888, the Earth is ruled by the PPF Empire . As the popul

Girls&#39; research HDU - 3294(马拉车水题)

题意: 求最长回文串 长度要大于等于2  且输出起点和终点  输出回文串字符 这个字符还是要以给出的字符为起点a 输出 解析: 分析一下s_new串就好了 #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include &l

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b