Gdut's lab.

Source: Internet
Author: User
Tags bitset decimal to binary
problem E:gdut's lab Description

As we all know, our Gudt Training Team Laboratory is very tall, it pulls a gigabit fiber, download speed up to ***m/s ... But the problem is, we all know that each computer will be assigned an IP address, These IP addresses are shaped like a.b.c.d, but the machine knows only binary, it will read the IP address as a binary address (only 1 and 0), but the machine will inevitably have some problems, now give you a decimal IP address, and then give you a machine translation of the binary IP address, ask whether the two addresses are the same. Input

Enter the first line to be an integer t, which means that there is a total of T-group data. (1<=t<=10000)

Next is the T-group data, each group of data takes two lines, the first line is the decimal IP address (a.b.c.d) (0<=a,b,c,d<=255), and the second line is the machine-translated binary IP address (XXXXXXXX. XXXXXXXX. XXXXXXXX. XXXXXXXX) ' X ' consists of ' 1 ' or ' 0 ', respectively

Output

The result outputs a T-line corresponding to the T-group data. The decimal IP address is the same as the binary IP address of the machine translation, output "Yes", otherwise output "No", note that the output is case-sensitive and has no quotation marks. Sample Input 2192.168.1.1 11000000.10101000.00000001.0000000 1 65.254.63.122 01000001.11111110.00111111.01111011 Sample Output Yes No HINT

#include <iostream>
#include <bitset>
using namespace Std;
int main ()
{
int a,b,c,d,t,s1,s2,s3,s4;
char x;
Bitset<32> e,f,g,l;
cin>>t;
while (t--)
{
cin>>a>>x>>b>>x>>c>>x>>d;
cin>>e>>x>>f>>x>>g>>x>>l;
S1=e.to_ulong ();
S2=f.to_ulong ();
S3=g.to_ulong ();
S4=l.to_ulong ();
if (S1==a&&s2==b&&s3==c&&s4==d)
cout<< "Yes" <<endl;
Else
cout<< "No" <<endl;
}
}

Note: "." Can be implemented in a way that defines a string. such as: Char X

Using the Bitest function, the decimal number can be converted directly into binary.

In addition, it is more convenient to convert decimal to binary.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.