给你一个有效的 IPv4 地址 address,返回这个 IP 地址的无效化版本。

所谓无效化 IP 地址,其实就是用 "[.]" 代替了每个 "."。

示例 1:

输入:address = "1.1.1.1"
输出:"1[.]1[.]1[.]1"
示例 2:

输入:address = "255.100.50.0"
输出:"255[.]100[.]50[.]0"

代码:

#include<iostream>
#include<cstring>
using namespace std;
int main(){
    string s;
    cin>>s;
    int len =s.length();
    for (int i = 0; i < len; i++)
    {
        int t = s.find(".",i);
        s.replace(t,1,"[.]");
        i=t+1;
    }
    cout<<s<<endl;
    
}

find(str, pos )

find(str, pos ,n)

 

相关文章:

  • 2021-07-20
  • 2021-07-09
  • 2021-10-13
  • 2021-11-18
  • 2021-05-17
  • 2021-04-18
猜你喜欢
  • 2022-03-03
  • 2022-12-23
  • 2021-11-01
  • 2021-12-08
  • 2021-05-15
  • 2022-01-11
  • 2021-09-11
相关资源
相似解决方案