We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Detecting Valid Latitude and Longitude Pairs
Detecting Valid Latitude and Longitude Pairs
+ 0 comments pattern=re.compile('([+-]?(([1-8][0-9]|[0-9])(.[0-9]+)?|90(.0+)?), [+-]?((1[0-7][0-9]|[1-9][0-9]|[0-9])(.[0-9]+)?|180(.0+)?))')
+ 0 comments import re n = int(input()) pattern = r"\A\([\-\+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s[\-\+]?([1-9]?\d(\.\d+)?|1[0-7]\d(\.\d+)?|180(\.0+)?)\)\Z" [print("Valid" if re.match(pattern, input()) is not None else "Invalid") for _ in range(n)]
+ 0 comments I'm not quite sure these problems should be considered easy anymore (You have way easier regex problems in the Python practice set). Here's the code in Python, which looks like an alien trying to communicate with us.
import re n_lines = int(input()) for _ in range(n_lines): print('Valid' if bool(re.match(r'\(([+-]?[0-8]?[0-9](\.[0-9]+)?|[+-]?90(\.0+)?), ([+-]?1[0-7][0-9](\.[0-9]+)?|[+-]?180(\.0+)?|[+-]?0?[0-9]?[0-9](\.[0-9]+)?)\)', input())) else "Invalid")
+ 0 comments Python 3
import re p = re.compile(r'\((\+|-)?([0-9](\.\d+)?|[1-8][0-9](\.\d+)?|90(\.0+)?), (\+|-)?([0-9](\.\d+)?|[1-9][0-9](\.\d+)?|1[0-7][0-9](\.\d+)?|180(\.0+)?)\)') for _ in range(int(input())): s = input() if bool(re.search(p,s)): print('Valid') else: print('Invalid')
+ 0 comments import re N = int(input()) for _ in range(N): LL = input() if re.search(r"^\([+-]?(([0-9]|[1-8][0-9])(\.\d+)?|90(\.0+)?), [+-]?(([0-9]{1,2}|1[0-7][0-9])(\.\d+)?|180(\.0+)?)\)",LL): print("Valid") else : print("Invalid")
Load more conversations
Sort 114 Discussions, By:
Please Login in order to post a comment