Light oj1354:IP Checking
来源:互联网 发布:葫芦娃爷爷阴谋 知乎 编辑:程序博客网 时间:2024/05/20 19:17
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);elseprintf("Case %d: Yes\n",j);}return 0; }
- Light oj1354:IP Checking
- Light OJ 1354 IP Checking
- Light OJ 1354 - IP Checking 【二进制转化】
- light oj 1354 IP Checking【进制转换】
- lightoj 1354 IP Checking
- lightoj 1354 - IP Checking
- lightoj1354 - 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 【字符串处理&&进制转化】
- lwip Light Weight (轻型)IP协议
- Light
- S3C2440 NAND Flash的使用
- 维度模型数据仓库(九) —— 角色扮演维度
- view getwidth() 和getMeasuredWidth()区别
- java中线程安全的讲解
- UVA 11987 Almost Union-Find (并查集)
- Light oj1354:IP Checking
- androdi studio之aidl文件生成
- 内存溢出(OOM)and内存泄露---及其解决
- 第三章 分支结构程序
- Python pickle 的 dump() & load()
- Android SDK下载和更新慢的解决方案
- 关于解决未在计算机注册Active控件或者没有Active控件的解决方法
- smarty 在linux 下display 显示空白
- [LeetCode] Single Number III