본문 바로가기

Algorithm/Code Fights (Code Signal)

Aracade Intro #21 isIPv4Address. Algorithm, 알고리즘, Codefights, CodeSignal, regx, 정규표현식, 코드파이트, 코드시그널, c++ java c# scalar


 Aracade Intro #21 isIPv4Address. Algorithm, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar



Q.


An IP address is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. There are two versions of the Internet protocol, and thus two versions of addresses. One of them is the IPv4 address.


IP주소는 각 장치들 마다 숫자로 라벨링된 것이고 (e.g. computer, printer) 연결을 위한 컴퓨터 네트워크의 Internet Protocol 을 따른다. 두가지 버전이 있는데, 그 중 한개가 IPv4 주소이다.


IPv4 addresses are represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255 inclusive, separated by dots, e.g., 172.16.254.1.


IPv4 주소들은 4개의 십진수 숫자와 온점 (.) 으로 나타내어지는데, 각 범위는 0 부터 255까지 되어있고, 점에 의해 분리되어있다. e.g. 172.16.254.1


Given a string, find out if it satisfies the IPv4 address naming rules.


주어진 문자열이 IPv4 주소 네이밍 형식에 맞는지 확인해라



e.g.


Input -> inputString = "172.16.254.1"


Output -> isIPv4Address(inputString) = true



Input -> inputString = "172.316.254.1"


Output -> isIPv4Address(inputString) = false.


316 is not in range [0, 255].



Input -> inputString = ".254.255.0"


Output -> isIPv4Address(inputString) = false.


There is no first number.





//Process (Regular Expression)

//1. input IPv4String

//2. get lines till every '.'

// 2.1. check if it's number or not, and then check if it's in between 0- 255

//  2.1.1. add to vector<string> tempString

//3. check tempString's length is 4, and if not,

// 4.1. answer = false

//5. output answer

//6. finish

// 




//Process (Regular Expression)

//1. input IPv4String

//2. get lines till every '.'

// 2.1. check if it's number or not, and then check if it's in between 0- 255

//  2.1.1. add to vector<string> tempString

//3. check tempString's length is 4, and if not,

// 3.1. answer = false

//6. output answer

//5. finish

// 


//처리과정 (정규표현식)

//1. inputString을 입력받는다.

//2. 입력받은 string을 . 단위로 끊어 읽는다.

// 2.1. Ipv4 기준에 맞는지 확인한다 (0~ 255)

//  2.1.1. 맞으면 -> tempString vector 에 더해둔다. (int count 로 바꿔도 될듯)

//3. count 가 4개가 아니면 false

//4. result를 반환한다.

//5. 끝낸다.



Code.. lemme see code!!!!!!!!


코드.. 코드를 보자!!!!!




bool isIPv4Address(std::string inputString) {

    

    std::stringstream stringStream(inputString);

    std::string segment;

    std::vector<string> stringList;

    std::regex regexNumber("[0-9]+");

    

    bool answer = true;

    

    while (std::getline(stringStream, segment, '.') && answer == true) 

    {

        if (std::regex_match(segment, regexNumber)

            && atoi(segment.c_str()) >= 0 && atoi(segment.c_str()) < 256) 

        {

            stringList.push_back(segment);

        }

        else {

            answer = false;

        }

    }

    if (stringList.size() != 4) 

    {

        answer = false;

    }

    return answer;

}




Something else....



2018/10/29 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #22 avoidObstacles. Algorithm, 알고리즘, Codefights, CodeSignal, regx, 정규표현식, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/28 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #21 isIPv4Address. Algorithm, 알고리즘, Codefights, CodeSignal, regx, 정규표현식, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/28 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #20 arrayMaximalAdjacentDifference. Algorithm, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/27 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #19 AreEquallyStrong. Algorithm, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #18 PalindromeRearranging, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #17 ArrayChange, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #16 AreSimilar?, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #15 AddBorder, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/20 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #14 AlternatingSums, Codefights, CodeSignal

2018/10/19 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #13 ReverseParentheses, Codefights, CodeSignal

2018/10/08 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #12 SortByHeight

2018/10/06 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #11 IsLucky

2018/10/03 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #10 CommonCharacterCount

2018/09/26 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #9 AllLongestStrings

2018/09/24 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #8 MatrixElementsSum

2018/09/23 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #7 AlmostIncreasingSequence

2018/09/22 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #6 MakeArrayConsecutive2

2018/09/21 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #5 ShapeArea

2018/09/19 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #4 AdjacentElementsProduct

2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #3 CheckPalindrome

2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #2 CenturyFromYear

2018/09/16 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #1 Add