Wednesday, 11 December 2019

1108. Defanging an IP Address


/*
Tanzila Islam
Website: https://sites.google.com/site/tanzilamohita
Email: tanzilamohita@gmail.com
*/

#include <bits/stdc++.h>
using namespace std;
 string defangIPaddr(string address) {
    string res;
    for (int i=0; i<address.size(); i++)
        {
            if (address[i] == '.')
                res += "[.]";
            else
                res.push_back(address[i]);
        }
        return res;
}
int main(){
string address;
cout << "Input: ";
cin >> address;

cout << "Output: " << defangIPaddr(address) <<endl;

}

No comments:

Post a Comment