题解 | #整数与IP地址间的转换#

整数与IP地址间的转换

http://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea

#include <stdio.h>
#include <string.h>

static unsigned int g_int[6] = {0};
int main(int argc, char** argv)
{
    scanf("%u.%u.%u.%u\n%u", &g_int[0], &g_int[1], &g_int[2], &g_int[3], &g_int[4]);
    for (int i = 0; i <= 3; i++) g_int[5] = g_int[5] * 256 + g_int[i];
    for (int i = 3; i >= 0; i--) {g_int[i] = g_int[4] % 256; g_int[4] /= 256;}
    printf("%u\n%u.%u.%u.%u\n", g_int[5], g_int[0], g_int[1], g_int[2], g_int[3]);
    return 0;
}
全部评论

相关推荐

仁者伍敌:实习生要工作经验,工作要实习经验
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 13:05
TMD找工作本来就烦,这东西什么素质啊😡
Beeee0927:hr是超雄了,不过也是有道理的
点赞 评论 收藏
分享
06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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