【字符串】1108. IP 地址无效化

题目:

解法:

 1 class Solution {
 2 public: 
 3     string defangIPaddr(string address) 
 4     {
 5         string res ;
 6 
 7         for ( char c : address )
 8         {
 9             if ( c == '.' )  
10             {
11                 res += "[.]" ;
12             }
13             else 
14             {
15                 res += c ;
16             }
17         }
18 
19         return res ;
20     }
21 };

猜你喜欢

转载自www.cnblogs.com/ocpc/p/12824397.html