题目链接

思路:这是一道非常简单的题目,直接用公式计算就好了。对于IP地址a.b.c.d,转换为十进制数就是(a<<24)|(b<<16)|(c<<8)|d。唯一要注意的就是这里需要用unsigned int来存数值。

AC代码:

 1 #include <cstdio>
 2  
 3 int main()
 4 {
 5     int n;
 6     unsigned int a, b, c, d;
 7     scanf("%d", &n);
 8     while (n--)
 9     {
10         scanf("%u.%u.%u.%u", &a, &b, &c, &d);
11         printf("%u\n", (a << 24) | (b << 16) | (c << 8) | d);
12     }
13     return 0;
14 }

 

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2019-09-10
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
猜你喜欢
  • 2021-10-18
  • 2022-03-07
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2022-03-02
相关资源
相似解决方案