当前位置:网站首页>"Daily practice, happy water" 1108 IP address invalidation

"Daily practice, happy water" 1108 IP address invalidation

2022-06-25 04:42:00 Who eats mints


Try to catch up with the original question :

1108. IP Address invalidation

* A brief introduction to the topic :

Give you an effective IPv4 Address address, Go back to this IP Invalid version of address .

The so-called invalidation IP Address , In fact, it is to use “[.]” Instead of every “.”.

* Their thinking :

  1. Simulation Dafa is good
  2. Traversal string , hold . Replace with [.] that will do
  3. over

*C++ Code :

class Solution {
    
public:
    string defangIPaddr(string address) {
    
        string ans;
        for (auto  c : address) {
    
            if (c == '.') {
    
                ans += "[.]";
            } else {
    
                ans.push_back(c);
            }
        }
        return ans;
    }
};

Result display :

 Insert picture description here

原网站

版权声明
本文为[Who eats mints]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250318209270.html