Powered by:NEFU AB-IN
原理:ip地址的每段可以看成是一个0-255的整数,把每段拆分成一个二进制形式组合起来,然后把这个二进制数转变成一个长整数。
输出转换成10进制的IP地址 输出转换后的IP地址
#include
using namespace std;
int main() {
long long int a, b, c, d;
long long int num;
while (scanf("%lld.%lld.%lld.%lld", &a, &b, &c, &d) != EOF) {
cin >> num;
cout << (a << 24) + (b << 16) + (c << 8) + d << endl;
a = num >> 24;
num = num - (a << 24);
b = num >> 16;
num = num - (b << 16);
c = num >> 8;
d = num - (c << 8);
cout << a << "." << b << "." << c << "." << d << endl;
}
}