题解 | #整数与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<<".";
        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-18 12:01
点赞 评论 收藏
分享
06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务