题目链接:https://leetcode-cn.com/problems/defanging-an-ip-address/
题目如下:
class Solution {
public:
string defangIPaddr(string address) {
int size=address.size();
int new_size=size+3*2;
address.resize(new_size);
int pos=new_size-1;
for(int i=size-1;i>=0;i--){
if(address[i]!='.') address[pos--]=address[i];
else {
address[pos--]=']';
address[pos--]='.';
address[pos--]='[';
}
}
return address;
}
};