思路:
只要理解一个数字不管用多少进制去计算,最后的结果都不会变,这道题就很简单了。
代码:
#include <iostream>
using namespace std;
typedef unsigned long long ULL;
int main(){
ULL res;
char ch;
ULL num1,num2,num3,num4;
cin>>num1>>ch>>num2>>ch>>num3>>ch>>num4;
cin>>res;
//十进制输出IP
ULL ans = (num1<<24)+(num2<<16)+(num3<<8)+num4;
cout<<ans<<endl;
//十六进制IP
num1 = res >> 24;
res = res - (num1 << 24);
num2 = res >> 16;
res = res - (num2 << 16);
num3 = res >> 8;
res = res - (num3 << 8);
cout<<num1<<'.'<<num2<<'.'<<num3<<'.'<<res;
}
评论区