2013 gzhu 校赛

题目描述:

                    IP Checking

    Time Limit: 2000/1000 MS (Java/Others)            Memory Limit: 128000/64000 KB (Java/Others)

Problem 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

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 "Yes" if they are same, otherwise print "No".

Sample Input

192.168.0.100
11000000.10101000.00000000.11001000
65.254.63.122
01000001.11111110.00111111.01111010

Sample Output

No
Yes

 

 
  死改死改死改!!!原来"No" 和 "Yes" 输出变成 "NO" 和 "YES" 了,而且还是问asdfgg的,瘀死了 = =!!记录下来是警醒自己以后不能再犯这种错误了!!!
 
 1 #include <iostream>
 2 #include <cstdio> 
 3 #include <cstdlib> 
 4 #include <cstring> 
 5 using namespace std;   
 6 
 7 const int maxn = 50; 
 8 char s2[maxn]; 
 9 int s[5];   
10 
11 int main() 
12 {     
13     char ch; 
14     int t1, t2, t3, t4, l1, l2, l, i, j, p, tmp;     
15     while (scanf("%d%c%d%c%d%c%d", &t1, &ch, &t2, &ch, &t3, &ch, &t4) != EOF)     
16     {         
17         scanf("%s", s2);         
18         l2 = strlen(s2);         
19         l1 = 7, l = tmp = 0;        
20         for (i = 0; i < l2; i++)        
21         {             
22             if (s2[i] != '.')            
23             {                 
24                 p = 1;                
25                 for (j = 1; j <= l1; j++)                   
26                     p *= 2;               
27                 tmp += p * (s2[i]-'0');                
28                 l1--;           
29              }             
30             else           
31             {                
32                 s[l++] = tmp;          
33                 tmp = 0;                
34                 l1 = 7;             
35             }         
36         }         
37         s[l++] = tmp;      
38         if (s[0] == t1 && s[1] == t2 && s[2] == t3 && s[3] == t4)           
39             printf("Yes\n");         
40         else            
41             printf("No\n");     
42     }     
43     return 0; 
44 } 

 

 
 
posted @ 2014-03-04 23:02  windysai  阅读(186)  评论(0编辑  收藏  举报