Description
众所周知,我们GUDT的集训队实验室很高大上,里面拉有千兆光纤,下载速度高达***M/s…但是问题来了,我们都知道每台电脑都会被分配一个IP地址,这些IP地址形如A.B.C.D,但是机器只懂得二进制,它会将IP地址读成二进制的地址(仅有1和0),但机器难免会出点问题,现在给你一个十进制的IP地址,再给你一个机器翻译后的二进制的IP地址,问这两个地址是否相同?
Input
输入第一个行是一个整数T,表示总共有T组数据。(1<=T<=10000)
接下来是T组数据,每组数据占两行,第一行是十进制的IP地址(A.B.C.D)(0<=A,B,C,D<=255),第二行是机器翻译过的二进制的IP地址(XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX) ‘X’分别由’1’或者’0’组成
Output
结果输出T行,对应T组数据。十进制的IP地址与机器翻译过的二进制IP地址相同,则输出”Yes”,否则输出”No”,注意,输出时注意大小写且没有引号。
Sample Input
2
192.168.1.1
11000000.10101000.00000001.00000001
65.254.63.122
01000001.11111110.00111111.01111011
Sample Output
Yes
No
题解:
水题,字符串处理
代码
#include <cstdio>
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
#define MAX 100000
#define LL long long
using namespace std;
int chage(string s)
{
int sum = 0;
int num = 1;
for(int i=s.size()-1; i>=0; i--)
{
sum = sum + num * (s[i]-'0');
num = num * 2;
}
return sum;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int s1[4];
string s2;
int s1temp[4];
char a;
cin >> s1[0] >> a >> s1[1] >> a >> s1[2] >> a>> s1[3];
cin >> s2;
int j = 0;
string s2temp[4];
s2temp[0] = s2.substr(0,8);
s2temp[1] = s2.substr(9,8);
s2temp[2] = s2.substr(18,8);
s2temp[3] = s2.substr(27,8);
s1temp[0] = chage(s2temp[0]);
s1temp[1] = chage(s2temp[1]);
s1temp[2] = chage(s2temp[2]);
s1temp[3] = chage(s2temp[3]);
int flag = 1;
for (int i = 0;i<4;i++)
if (s1temp[i] == s1[i])
continue;
else
{
flag = 0;
cout << "No" << endl;
break;
}
if (flag)
cout << "Yes" << endl;
}
return 0;
}
--------------------- 本文来自 围巾的ACM 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/qq_21057881/article/details/50241325?utm_source=copy