当前位置:网站首页>1108. Defanging an IP Address
1108. Defanging an IP Address
2022-06-22 05:10:00 【SUNNY_ CHANGQI】
The description of the problem
Given a valid (IPv4) IP address, return a defanged version of that IP address.
A defanged IP address replaces every period "." with "[.]".
source : Power button (LeetCode)
link :https://leetcode.cn/problems/defanging-an-ip-address
an example
Input: address = "1.1.1.1"
Output: "1[.]1[.]1[.]1"
The codes for above problem
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Solution {
public:
string defangIPaddr(string address) {
// split the address by '.' into a vector
string res = "";
vector<string> address_parts;
string part;
while (find(address.begin(), address.end(), '.') != address.end()) {
part = address.substr(0, address.find('.'));
address_parts.emplace_back(part);
address.erase(0, address.find('.') + 1);
}
for (auto address_part : address_parts) {
res += address_part + "[.]";
}
res += address;
return res;
}
};
int main()
{
Solution s;
string address = "255.100.50.0";
cout << "The defanged address is: " << s.defangIPaddr(address) << endl;
return 0;
}
The corresponding codes
$ ./test
The defanged address is: 255[.]100[.]50[.]0

边栏推荐
- 使用matplotlib实现GUI交互效果
- [user guide] use of Tsinghua source
- 10 "no no no" redis interview questions
- Storage mode and lifetime of C language variables
- C language data type conversion rules (implicit conversion + explicit conversion)
- Reading notes on how MySQL works [updating]
- Pull down refresh, push up load (easy to use, finally)
- 1108. Defanging an IP Address
- Web design and production final assignment report - minority music website
- MySQL day03 class notes
猜你喜欢

10 "no no no" redis interview questions

1108. Defanging an IP Address

并发编程——线程池

A domestic developer opened the "programmer's Guide to cooking" and became popular!

Non recursive printing Fibonacci sequence

9 practical shell scripts, recommended collection!

使用matplotlib实现GUI交互效果

使用选择法对十个整数进行排序

Qt保存QTextEdit内存至.txt文件中

C语言变量的存储方式和生存期
随机推荐
Zhongmin online: sharing online channel resources with "points" as the link
第6章无穷级数_傅立叶级数
C语言数据类型转换规则(隐式转换+显式转换)
Solve the shortage of developers. Maybe it can help you
Reading notes on how MySQL works [updating]
Flink deployment mode (I) - standalone and Application
使用matplotlib实现GUI交互效果
JUC - thread interrupt and thread waiting and wakeup (locksupport)
Compilation des connaissances communes de la base de données numpy
IQueryable和IEnumerable的区别
[scientific research notes] focal loss
uwsgi-invalid-request-block-size invalid request block size: 21327 (max 4096)... Skip solution
【chrome】 谷歌小技巧 谷歌浏览器 自带 滚动截图(全屏截图)
In 2022, the super intern plans to make a breakthrough in the offer of it famous enterprises, and the nine high salary skills help the dream of famous enterprises
6. Local - custom filter factory
liunx虚拟机环境使用docker安装oracle数据库,并使用navicat连接
并发编程——线程池
flink部署模式(二)- yarn三种部署模式
花式优化器整理
VirtualBox 6.1.34 发布