0
Do if u can
if a user gives an input of characters then u have to find a maximum no forming in it for ex input °-;℅&72^¢62;*:^£℅ output highest no is 72 2) input -#-6#-2Π¢°`÷°¢i output highest no -2 At least try and keep posting... let us see who will make a best one
7 Respostas
+ 5
# Python solution (updated to handle negative numbers):
import re
inp1 = "°-;℅&72^¢62;*:^£℅"
inp2 = "-#-6#-2Π¢°`÷°¢i"
rgxp = r"-?\d+"
def numbers(txt):
num = re.findall(rgxp,txt)
num = [int(x) for x in num]
return num
print(max(numbers(inp1)))
print(max(numbers(inp2)))
+ 4
My try in Java, using regex.
https://code.sololearn.com/c31en5hT82LX/?ref=app
+ 2
# Second example shouldn't be 6 rather than 2?
# Python solution:
import re
inp1 = "°-;℅&72^¢62;*:^£℅"
inp2 = "-#-6#-2Π¢°`÷°¢i"
rgxp = r"\d+"
def numbers(txt):
num = re.findall(rgxp,txt)
num = [int(x) for x in num]
return num
print(max(numbers(inp1)))
print(max(numbers(inp2)))
+ 2
Oh: I doesn't understood that you want negative numbers too ^^
Just use:
rgxp = r"-?\d+"
instead the previous one ;)
+ 2
full that i can run
i am not good at Python now!!
+ 2
Just copy-paste the code and run it ^^
0
no the answer should be -2 only