当前位置:网站首页>1108. IP 地址无效化
1108. IP 地址无效化
2022-06-09 09:28:00 【Mr Gao】
1108. IP 地址无效化
给你一个有效的 IPv4 地址 address,返回这个 IP 地址的无效化版本。
所谓无效化 IP 地址,其实就是用 “[.]” 代替了每个 “.”。
示例 1:
输入:address = “1.1.1.1”
输出:“1[.]1[.]1[.]1”
示例 2:
输入:address = “255.100.50.0”
输出:“255[.]100[.]50[.]0”
这题也是很简单,我们设置一个3*strlen(address)内存的辅助字符串数组,就可以很好的解决问题,注意,最后要设置字符串数组s[end]=‘\0’,这个很重要。
解题代码如下:
char * defangIPaddr(char * address){
int len=strlen(address);
char *s =(char*)malloc(sizeof(char)*3*len);
int i=0;
int j=0;
while(address[i]!='\0'){
if(address[i]=='.'){
s[j++]='[';
s[j++]='.';
s[j++]=']';
}
else{
s[j++]=address[i];
}
i++;
}
s[j]='\0';
return s;
}
边栏推荐
- 视觉SLAM总结——SuperPoint / SuperGlue
- MSF module search details
- 【线性代数】理解正定矩阵和半正定矩阵
- 【实战技能】Google I/O 2022大会AI/ML给开发者的启发
- 八、线性规划 顶点、极值点和基本可行解决方案
- MSF基于SSH协议的信息收集
- Openstack explanation (12) -- glance installation and Preliminary Configuration
- Changan chain chainmaker multi machine environment
- 【新手上路常见问答】如何用TensorFlow玩转深度学习?
- Visual slam Summary - superpoint / superglue
猜你喜欢
![[linear algebra] understand positive definite matrix and semi positive definite matrix](/img/e0/fa9378a7d136f7d9a62ea3934e496d.png)
[linear algebra] understand positive definite matrix and semi positive definite matrix

循环神经网络理论——【torch学习笔记】

【 science, Technology, Business and management】 play Science and entrepreneurship: The Silicon Valley Saison 5 episodes 4 - 6

LeetCode_ Binary tree_ Prefix and_ Medium_ 437. path sum III

Learn about graph database neo4j (I)
![[5机器学习]全网最易懂的决策树(附源码)](/img/cb/815850c5c6ed2b3c20c8ba34caa7d8.png)
[5机器学习]全网最易懂的决策树(附源码)

机器学习笔记 - Transformer/Attention论文解读

openstack详解(十二)——Glance安装与初步配置

Moral and regulatory knowledge of data science

Neo4j realizes social recommendation (V)
随机推荐
Array. Map() shorthand function
[probability theory] correlation calculation between variables
- Bean method ‘redisConnectionFactory‘ in ‘JedisConnectionConfiguration‘ not loaded because @Conditi
LeetCode_ Monotone stack_ Medium_ 581. shortest unordered continuous subarray
机器学习笔记 - 什么是BLEU分数?
Understand the graph database neo4j (II)
【图机器学习】图神经网络入门(一)谱图理论
Redis info command memory information description
Openstack explanation (XX) -- neutron node principle
MSF backdoor attack against FTP
机器学习笔记 - 探索 keras 数据集
【科技、商业和管理】看剧学创业:《硅谷》第五季第1-3集
Understand the graph database neo4j (III)
[good book recommendation] popular science book of chip industry: core affairs
【好书推荐】芯片产业科普书籍:《芯事》
Benefits of TS generic classes and generic interfaces
NIO BIO AIO
DNMAP架构实现和扫描实战
如何管理云计算平台用户?
Machine learning notes - Introduction to R language learning series I