acm hnu 10049 IP Address

本文介绍了一种将32位二进制IP地址转换为十进制点分表示法的方法,并提供了一个简单的C语言实现示例。
IP Address
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 254, Accepted users: 239
Problem 10049 : No special judgement
Problem description
Suppose you are reading byte streams from any device, representing IP addresses. Your task is to convert a 32 characters long sequence of '1s' and '0s' (bits) to a dotted decimal format. A dotted decimal format for an IP address is form by grouping 8 bits at a time and converting the binary representation to decimal representation. Any 8 bits is a valid part of an IP address. To convert binary numbers to decimal numbers remember that both are positional numerical systems, where the first 8 positions of the binary systems are:

27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1

Input
The input will have a number N (1<=N<=9) in its first line representing the number of streams to convert. N lines will follow.

Output
The output must have N lines with a doted decimal IP address. A dotted decimal IP address is formed by grouping 8 bit at the time and converting the binary representation to decimal representation.

Sample Input
4
00000000000000000000000000000000 
00000011100000001111111111111111 
11001011100001001110010110000000 
01010000000100000000000000000001 
Sample Output
0.0.0.0
3.128.255.255
203.132.229.128
80.16.0.1
Problem Source
MCA 2004

code:

/*start 17:43*/
/*end 18:08  25min*/
#include 
<stdio.h>
#include 
<string.h>

main()
{
      
int n,i,j,p,dec=0;
      
char s[32];
      scanf(
"%d",&n);     
      
      
for( i = 0 ; i < n ; i++ ){
           scanf(
"%s",s);
           
for( j = 0,p = 7 ; j < 32 ; j++,p--){

  
                    
if(s[j]=='1')dec+=pow(2,p);    
                    
if( p == 0 ){
                        p
=8;
                        printf(
"%d",dec);
                        dec
=0;
                        
if(j == 31)printf(" ");
                        
else printf(".");
                    }  
 
                
           }
      }
      
      system(
"PAUSE");
}

 

### HNU ACM 2024 Competition Information and Team Details HNU ACM团队积极参与各类编程竞赛活动,旨在提升成员算法设计与实现能力。对于即将举行的2024年比赛,参赛者需关注官方渠道发布的最新通知来获取确切的比赛时间表、规则变化以及报名方式等重要信息[^1]。 #### 团队构成 该队伍由来自不同年级的学生组成,他们拥有丰富的解题经验和扎实的理论基础,在历届赛事中取得了优异的成绩。新老队员之间相互学习交流,共同进步成长。此外,学校还邀请了多位经验丰富的指导教师参与培训工作,帮助学生更好地准备比赛。 #### 训练资源 为了提高选手们的实战水平,HNU ACM提供了多种训练途径: - **在线评测平台**:通过解决平台上提供的题目积累经验; - **内部讲座和技术分享会**:定期举办专题研讨会,深入探讨特定领域内的难题解决方案; - **模拟赛**:不定期组织校内选拔测试或与其他高校联合举行友谊对抗赛,增强团队协作精神的同时也锻炼心理素质。 #### 技术栈覆盖范围广泛 除了传统的数据结构和算法外,还包括但不限于以下方面: - 动态规划的应用实例解析,例如在处理分硬币问题时如何构建状态转移方程以求得最优解法。 - C/C++语言特性及其高效利用技巧,比如理解不同类型变量之间的转换机制,避免因误操作而导致不可预期的结果输出[^2]。 - 操作系统的底层原理探索,像掌握FIFO缓冲区的工作模式及相应寄存器的状态监测方法[^3]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值