Light oj1354:IP Checking
2015-11-08 14:55
429 查看
D - 楼上正解
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status Practice LightOJ
1354
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
AC-code:
此代码有点复杂。。。。。。
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status Practice LightOJ
1354
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
AC-code:
此代码有点复杂。。。。。。
#include<cstdio> #include<cstring> int main() { int a,b,c,t,d,i,len,j,k,q,flag,p,a1,b1,c1,d1; char str[40],str1[10],str2[10],str3[10],str4[10]; scanf("%d",&t); for(j=1;j<=t;j++) { flag=1; scanf("%d.%d.%d.%d",&a,&b,&c,&d); scanf("%s",str); len=strlen(str); i=0; a1=k=p=q=0; while(str[i]!='.'&&str[i]!='\0') { str1[a1++]=str[i++]; } str1[a1]='\0'; i++; while(str[i]!='.'&&str[i]!='\0') str2[k++]=str[i++]; i++; while(str[i]!='.'&&str[i]!='\0') str3[p++]=str[i++]; i++; while(str[i]!='.'&&str[i]!='\0') str4[q++]=str[i++]; k=0; while(str1[k]=='0') k++; b1=c1=d1=a1=0; for(;k<8;k++) { if(str1[k]=='0') continue; p=1; for(i=0;i<7-k;i++) p*=2; a1+=p; } if(a1!=a) flag=0; else { k=0; while(str2[k]=='0') k++; for(;k<8;k++) { if(str2[k]=='0') continue; p=1; for(i=0;i<7-k;i++) p*=2; b1+=p; } if(b1!=b) flag=0; else { k=0; while(str3[k]=='0') k++; for(;k<8;k++) { if(str3[k]=='0') continue; p=1; for(i=0;i<7-k;i++) p*=2; c1+=p; } if(c1!=c) flag=0; else { k=0; while(str4[k]=='0') k++; for(;k<8;k++) { if(str4[k]=='0') continue; p=1; for(i=0;i<7-k;i++) p*=2; d1+=p; } if(d1!=d) flag=0; } } } if(!flag) printf("Case %d: No\n",j); else printf("Case %d: Yes\n",j); } return 0; }
相关文章推荐
- view getwidth() 和getMeasuredWidth()区别
- java中线程安全的讲解
- 程序猿书单--转载
- 转自一个CG大神的文章
- D3.js数据可视化(三)——地图可视化
- 二叉树的各种遍历算法的递归和非递归实现
- S3C2440 NAND Flash的使用
- C++实现动态绑定代码分享
- 一个关于二维指针的问题
- 数据结构实验之栈八:栈的基本操作
- Property's synthesized getter follows Cocoa naming convention for returning
- nyoj62笨小熊
- python之模块calendar(汇集了日历相关的操作)
- C++中静态变量、常量、静态整型常量、静态非整型常量、引用变量的初始化方法
- 数据结构实验之栈七:出栈序列判定
- 第二章 运算和数据类型
- Concordion test
- 欢迎使用CSDN-markdown编辑器
- ubuntu10.4NFS挂载到mini2440相关问题
- Redis3.0.5学习笔记(一)基础入门