본문 바로가기

Algorithm/Code Fights (Code Signal)

Aracade Intro #27 variableName. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

 Aracade Intro #27 variableName. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar



Q.

 Correct variable names consist only of English letters, digits and underscores and they can't start with a digit.


Check if the given string is a correct variable name.


 변수명으로 옳은 것은 알파벳, 숫자, 언더바로만 이루어져 있고, 시작은 숫자로 할 수 없다.

옳은 변수명인지 확인하라.



e.g.


 For name = "var_1__Int", the output should be

variableName(name) = true;


For name = "qq-q", the output should be

variableName(name) = false;


For name = "2w2", the output should be

variableName(name) = false.



You can use regular expression for code easy to read

정규표현식 쓰면 코드 깔끔할듯


This one is using ascii

아스키로 조건줘서 푼 것으로 내비뒀음



//Process

//1. Input string name

//2. Check if first char is Alphabet or underscore

// 2.1. If so -> Iterate from begin+1 to end

//  2.1.1. Check if i is Latin letter, digit, or underscore

//   2.1.1.1. If not -> answer is false

//3. Return answer

//4. Finish



//처리과정

//1. 변수명을 입력받는다.

//2. 첫글자가 알파벳이나 언더바인지 확인해서

// 2.1. 맞으면 -> 시작부터 반복한다.

//  2.1.1. 알파벳, 숫자, 언더바인지 확인해서

//   2.1.1.1. 아니면 -> false return

//3. Return true

//4. Finish



Code.. Lemme see code..


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




bool variableName(std::string name) {

    

    int length = name.size();

    

    char letter = name[0];

    if ((name[0] >= 'a' && name[0] <= 'z') || (name[0] >= 'A' && name[0] <= 'Z') || name[0] == '_') 

    {

        for (int i = 1; i < length; ++i) 

        {

            if (!(name[i] >= 'a' && name[i] <= 'z') || 

                !(name[i] >= 'A' && name[i] <= 'Z') ||

                name[i] != '_' || 

                !(name[i] >= '0' && name[i] <= '9')) 

            {

                // check the reverse conditions

            }

            else {

                return false;

            }

        }

    }

    else {

        return false;

    }    

    return true;

}




Something else...




2018/11/14 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #26 evenDigitsOnly. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

2018/11/11 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #25 arrayReplace. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

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

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

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