Skip to content

Uploading First Time #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions C++/Defanging an IP Address.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*Given a valid (IPv4) IP address, return a defanged version of that IP address.
A defanged IP address replaces every period "." with "[.]".*/

/* Input: address = "1.1.1.1"
Output: "1[.]1[.]1[.]1"*/

#include<bits/stdc++.h>
class Solution {
public:
string defangIPaddr(string address) {
string op;
//A for loop which will execute till the address[i] which means the string runs till the last character of the string is Null
for(int i=0;address[i]!='\0';i++)
{
//if address[i]== '.' which means that if the in a string contains a period we'll replace it with [.]
if(address[i]=='.')
{
//This line adds the square brackets if there's a period in a string
op=op+'['+ address[i]+']';
i++;

}
op=op+address[i];

}
return op;
}
};