Light OJ 1354 - IP Checking 【二进制转化】
来源:互联网 发布:玻璃优化排版软件 编辑:程序博客网 时间:2024/05/30 22:59
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
恩,就是让比较两者形式的IP是否一样。简单的二进制转化。
#include <iostream>#include<cstdio>#include<cstring>using namespace std;int s[5][10];char str[50];int rec[9]={1,2,4,8,16,32,64,128,256};int tran(int a[]){ int s=0; for(int i=7;i>=0;i--) s=s+a[i]*rec[7-i]; return s;}int main(){ int t,a,b,c,d,cnt=0; scanf("%d",&t); while(t--) { scanf("%d.%d.%d.%d",&a,&b,&c,&d); scanf("%s",str); int len=strlen(str); int j=0; for(int i=0;i<len;++i) { int k=0; while(i<len&&str[i]!='.') { s[j][k++]=str[i]-'0'; i++; } j++; } printf("Case %d: ",++cnt); int aa=tran(s[0]); int bb=tran(s[1]); int cc=tran(s[2]); int dd=tran(s[3]); if(aa==a&&bb==b&&cc==c&&dd==d) printf("Yes\n"); else printf("No\n"); } return 0;}
- Light OJ 1354 - IP Checking 【二进制转化】
- Light OJ 1354 IP Checking
- light oj 1354 IP Checking【进制转换】
- Light oj1354: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 1116 Ekka Dokka(数学,二进制的应用)
- LightOJ 1354 - IP Checking【简单模拟】
- lightoj--1354--IP Checking(水题)
- light oj
- light oj
- Light OJ
- strstr和strchr的区别
- Nginx的使用入门
- LINUX 系统运维转向运维开发
- 归档
- poj 1631 Bridging signals dp LIS
- Light OJ 1354 - IP Checking 【二进制转化】
- 数据结构基础5.3:平衡二叉树(AVL树)的调整
- ApplicationOnline_Tips&Review
- HDU 1401 Solitaire
- Physics.IgnoreLayerCollision没有效果
- 有序数组的查询
- Java第一次写的流布局图形界面,留个纪念
- zufe oj Problem H: 简单数学题 java
- Git基础操作<二>