lightoj 1354 IP Checking
来源:互联网 发布:希尔伯特矩阵 编辑:程序博客网 时间:2024/05/29 17:26
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 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
2
192.168.0.100
11000000.10101000.00000000.11001000
65.254.63.122
01000001.11111110.00111111.01111010
Sample Output
Case 1: No
Case 2: Yes
#include <iostream>#include <cstdio>#include <cstring>#include <sstream>using namespace std;int a,b,c,d,aa,bb,cc,dd;string str,aaa,bbb,ccc,ddd;int change(string t){ int ret=0; for(int i=0;i<t.size();i++) ret=ret*2+t[i]-'0'; return ret;}int main(){ int T; scanf("%d",&T); for(int co=1;co<=T;co++) { scanf("%d.%d.%d.%d",&a,&b,&c,&d); getchar(); getline(cin,str); for(int i=0;i<str.size();i++) if(str[i]=='.') str[i]=' '; stringstream ss(str); ss>>aaa>>bbb>>ccc>>ddd; aa=change(aaa); bb=change(bbb); cc=change(ccc); dd=change(ddd); if(a==aa && b==bb && c==cc && d==dd) printf("Case %d: Yes\n",co); else printf("Case %d: No\n",co); } return 0;}
- lightoj 1354 IP Checking
- lightoj 1354 - IP Checking
- LightOJ 1354 - IP Checking
- LightOJ 1354 - IP Checking
- lightoj 1354 - IP Checking
- lightoj 1354 - IP Checking 【进制水题】
- LightOJ 1354 IP Checking (水)
- LightOJ 1354 - IP Checking【简单模拟】
- lightoj--1354--IP Checking(水题)
- lightoj 1354 - IP Checking (进制转换)
- lightOJ 1354 - IP Checking 【字符串处理&&进制转化】
- Light OJ 1354 IP Checking
- Light OJ 1354 - IP Checking 【二进制转化】
- Light oj1354:IP Checking
- lightoj1354 - IP Checking
- light oj 1354 IP Checking【进制转换】
- lightoj 1354
- LightOJ
- android小知识3
- Linux基本数据类型大小——int,char,long int,long long int
- C++ primer 第五版 中文版 练习 12.6 个人code
- live555-计划任务(TaskScheduler)深入探讨
- Bowtie2使用方法与参数详细介绍
- lightoj 1354 IP Checking
- 123
- 黑马程序员--IO流之字符流
- Linux内核编译 Ubuntu系统
- make a mobile robot
- iOS开发工具系列(按功能分)
- php引用(&)详解及注意事项
- MATLAB图像处理基础知识
- Longest Run on a Snowboard+uva+dp记忆化搜索