YUYANE

Python/ HackerRank Detect Floating 본문

Programming Theory/Algorithm

Python/ HackerRank Detect Floating

YUYA 2021. 1. 6. 16:27

문제

 

www.hackerrank.com/challenges/introduction-to-regex/problem?h_r=internal-search

 

Detect Floating Point Number | HackerRank

Validate a floating point number using the regular expression module for Python.

www.hackerrank.com

 

해결 코드

T = int(input())
nums = []


def detect(a):

    if '.' in a:
        idx = a.find('.')
        try:
            float(a)
            if len(a) > idx:
                value = a[idx+1]
                try:
                    int(value)
                    return True
                except:
                    return False
        except:
            return False
    else:
        return False


for i in range(T):
    num = input()
    nums.append(num)

for i in range(len(nums)):
    print(detect(nums[i]))

 

겪었던 어려움

 

1y9u9j2in.tistory.com/120

 

Python/ 문자열에서 특정 인덱스 값 다음의 문자를 찾을 때 유의

전체 코드 T = int(input()) nums = [] def detect(a): if '.' in a: idx = a.find('.') try: float(a) return a[idx+1] except: return False else: return False for i in range(T): num = input() nums.append(..

1y9u9j2in.tistory.com

 

'Programming Theory > Algorithm' 카테고리의 다른 글

알고리즘 / 계수 정렬  (0) 2021.01.25
알고리즘 / 삽입 정렬  (0) 2021.01.23
알고리즘 / 선택 정렬  (0) 2021.01.22
Python/ HackerRank Find the Runner-Up Score!  (0) 2021.01.11
JAVA / charAt() (백준 11720 자바)  (0) 2020.11.26
Comments