题解 | #整数与IP地址间的转换#
整数与IP地址间的转换
https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea
#include <iostream>
using namespace std;
#include<stack>
int main() {
unsigned int temp;
unsigned int ip10=0;
stack<int>ip;
int n=4;
while(n--)
{
cin>>temp;
ip10=ip10*256+temp;
getchar();
}
n=4;
cin>>temp;
while(n--)
{
ip.push(temp%256);
temp=temp/256;
}
cout<<ip10<<endl;
while(1)
{
cout<<ip.top();
ip.pop();
if(ip.empty())
{
break;
}
else
{
cout<<".";
}
}
}