From 3c4bec38153355ef311f2fcd6c5bf2cb85749fc6 Mon Sep 17 00:00:00 2001 From: sn0716 Date: Thu, 18 May 2023 10:24:02 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98]=EC=9D=B4?= =?UTF-8?q?=EC=A7=84=EB=B3=80=ED=99=98=EB=B0=98=EB=B3=B5=ED=95=98=EA=B8=B0?= =?UTF-8?q?-=EB=82=98=EC=9D=98=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- argorithm/.idea/argorithm.iml | 2 +- argorithm/.idea/misc.xml | 2 +- ...30\353\263\265\355\225\230\352\270\260.py" | 42 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 "argorithm/\354\235\264\354\247\204\353\263\200\355\231\230\353\260\230\353\263\265\355\225\230\352\270\260.py" diff --git a/argorithm/.idea/argorithm.iml b/argorithm/.idea/argorithm.iml index 644da3b..74d515a 100644 --- a/argorithm/.idea/argorithm.iml +++ b/argorithm/.idea/argorithm.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/argorithm/.idea/misc.xml b/argorithm/.idea/misc.xml index 1e28675..d1e22ec 100644 --- a/argorithm/.idea/misc.xml +++ b/argorithm/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git "a/argorithm/\354\235\264\354\247\204\353\263\200\355\231\230\353\260\230\353\263\265\355\225\230\352\270\260.py" "b/argorithm/\354\235\264\354\247\204\353\263\200\355\231\230\353\260\230\353\263\265\355\225\230\352\270\260.py" new file mode 100644 index 0000000..968a7ae --- /dev/null +++ "b/argorithm/\354\235\264\354\247\204\353\263\200\355\231\230\353\260\230\353\263\265\355\225\230\352\270\260.py" @@ -0,0 +1,42 @@ +def removeZero(val): + removedZeroCnt = 0 + for index, i in enumerate(val): + if i == '0': + removedZeroCnt += 1 + return removedZeroCnt, ''.join(val).replace('0', '') + +def transform(val): + namosi = [] + while val != 1: + rest = val % 2 + val = val // 2 + namosi.append(str(rest)) + namosi.append('1') + namosi.reverse() + return namosi + +def solution(s): + answer = [] + zeroCnt = 0 + transCnt = 0 + listedVal = list(s) + while listedVal: + # 0 제거 + removedZeroCnt, val = removeZero(listedVal) + print(removedZeroCnt, val) + zeroCnt += removedZeroCnt + # 0 제거 후 길이 확인 + removedStringLen = len(val) + print(removedStringLen) + # 이진 변환 + listedVal = transform(removedStringLen) + transCnt += 1 + if len(listedVal) == 1 and listedVal[0] == "1": + break + answer.append(transCnt) + answer.append(zeroCnt) + return answer + +if __name__ == '__main__': + result = solution("110010101001") + print(result) \ No newline at end of file