ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Cipher_Zeroes [Decimal to Binary]
    myCode/ShortestCodeChallenge 2016. 6. 4. 14:04

    https://codefights.com/challenge/x9TcPgiFRmgN22W44/main





    1000


    Nicky and Dev work in a company where each member is given his income in the form of points. On Nicky's birthday, Dev decided to give some of his points as a gift. The number of points Dev is gifting is the total number of visible zeros visible in the string representation of the N points he received this month.

    Let's say that Nicky got M points from Dev. By the company law, if M is even and greater than 0, Nicky must give one point to the company. If M is odd, the company gives Nicky one additional point.

    Given the number of points N Dev received this month, calculate the number of points Nicky will receive as a gift and return this number in its binary form.

    Note: visible zeros are calculated as follows:

    • 06 and 9 contain 1 visible zero each;
    • 8 contains 2 visible zeros;
    • other digits do not contain visible zeros.

    Example

    For N = "565", the output should be
    Cipher_Zeroes(N) = 10.

    There's one visible zero in "565". Since one is odd, the company will give an additional point, so Nicky will receive 2 points.
    210 = 102, so the output should be 10.






    설명문이 길지만 정작 문제에 필요한 조건은 몇 개 없다.


    문자열이 주어졌을 때, 그 문자열 내의 특정 조건 (여기서는 0,6,9,8 등의 특정 숫자) 을 찾아내는 것이고


    그리고 십진수를 이진수로 변환하는 것.


    문제는 매우 쉬우나


    중요한건 얼마나 효율적으로 짜는가의 방법.



    실제 순위권들을 보면 거의 100 문자 쯤으로 다 완료해낸다. 어떻게 한걸까.








    우선 십진법 -> 이진법으로 숫자를 바꾸는 코드


    주어진 숫자 dec를 계속해서 2로 나누면서 나머지를 자릿수를 올라가면서 더해가면 된다.


    'myCode > ShortestCodeChallenge' 카테고리의 다른 글

    EvenNumbers  (0) 2016.07.04
    Reverse_t9  (0) 2016.06.08
    Turns on Road  (0) 2016.05.17
    Anagram  (0) 2016.05.14
    Bridge  (0) 2016.05.11
Designed by Tistory.