forked from miczar1/djfz-24_25
Solve TaskC37
Bore...
This commit is contained in:
parent
8b27cc30c1
commit
ef7a470ae5
@ -22,7 +22,7 @@ bądź NNN-NN-NN. Jeśli napis nie spełnia podanych warunków, należy wypisać
|
||||
"<NONE>".
|
||||
|
||||
For each string, extract an area code from the phone number.
|
||||
We assume, that the phone number is two digits, is preceded by zero or plus.
|
||||
We assume, that the area code(?) is two digits, is preceded by zero or plus.
|
||||
The rest of the phone number is 7 digits written in N-NNN-NNN
|
||||
or NNN-NN-NN form.
|
||||
If the string does not fulfill the condition, you should print "<NONE>".
|
||||
|
14
TaskC37/solution.py
Normal file
14
TaskC37/solution.py
Normal file
@ -0,0 +1,14 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
def extract_area_code(line: str) -> str:
|
||||
# While this regex seems complicated, it essentially enforces either of two possible formats
|
||||
# Returning the area code captured in group(1)
|
||||
p = re.compile(r'^[+0](\d{2})\s(?:\d-\d{3}-\d{3}|\d{3}-\d{2}-\d{2})$')
|
||||
m = p.match(line)
|
||||
return m.group(1) if m else "<NONE>"
|
||||
|
||||
if __name__ == "__main__":
|
||||
for line in sys.stdin:
|
||||
stripped_line = line.strip()
|
||||
print(extract_area_code(stripped_line))
|
9
TaskC37/test.out
Normal file
9
TaskC37/test.out
Normal file
@ -0,0 +1,9 @@
|
||||
<NONE>
|
||||
61
|
||||
61
|
||||
61
|
||||
61
|
||||
82
|
||||
<NONE>
|
||||
<NONE>
|
||||
<NONE>
|
Loading…
Reference in New Issue
Block a user