当前位置:网站首页>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

边栏推荐
- How to deal with too small picture downloaded from xuexin.com
- php正则怎么去掉括号内容
- Debugging wechat built-in browser with chrome
- 获取DPI函数返回值永远是96 | 获取DPI函数返回值不正确 | GetDpiForMonitor/GetDeviceCaps返回值不正确的原因
- What is cloud hosting and what are its advantages?
- Monorepo silk slide methodology: reference module hot update
- Disturbed when programmers are programming? Daily anecdotes
- Zhongmin online: sharing online channel resources with "points" as the link
- Progress information collection for progress control of Zhiyuan project management SPM system
- [chrome] Google tips Google browser comes with scrolling screenshot (full screen shot)
猜你喜欢

Remote dictionary server (redis) - a kV based NoSQL database management system used as a cache

Exness: ECB president Christine Lagarde reiterated her plan to raise interest rates at the July meeting

Non recursive printing Fibonacci sequence

Getting the return value of DPI function is always 96 | getting the return value of DPI function is incorrect | why the return value of getdpiformonitor/getdevicecaps is incorrect

What problems will be encountered during the implementation of MES management system

10 "no no no" redis interview questions

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

Accelerate the promotion of industrial Internet, and map out a new blueprint for development
Please, use three JS make 2D pictures have 3D effect cool, OK

Lottie components make animation easier
随机推荐
In 2022, the postgraduate entrance examination ran aground | how to counter attack famous IT enterprises and become a programmer in three months
CS 611 Game
It is easy to analyze and improve R & D efficiency by understanding these five figures
9 practical shell scripts, recommended collection!
MySQL notes
IDP depth | what kind of data analysis and mining tools do enterprises need?
Zset type of redis
IQueryable和IEnumerable的区别
图扑软件2D与2.5D案例合集|智慧园区、数据中心、SMT 生产线...
What is cloud hosting and what are its advantages?
numpy庫常用知識整理
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
Non recursive printing Fibonacci sequence
DTS迁移秘籍-Oracle篇
Concurrent programming - thread pool
How much is London gold
基于深度学习的目标检测算法面试必备(RCNN~YOLOv5)
【sdx62】QCMAP_ CLI manual dialing instructions
mysql day02课堂笔记
10 "no no no" redis interview questions