題二:
答案:
#coding=utf-8
import re,sys
str = sys.stdin.readline().strip()
def regex(str):
result = ""
if re.sub(r'^::/128$|^([0]{4}:){7}[0]{4}$', r'Unspecified', str) == 'Unspecified':
result = 'Unspecified'
elif re.sub(r'^::1/128$|^([0]{4}:){7}[0]{3}1$', r'Loopback', str) == 'Loopback':
result ='Loopback'
elif re.sub(r'^FE80::/10$|^FE[8AB]{1}[0-9A-F]{1}(:[0-9A-F]{4}){6}:[0-9A-F]{4}$', r'LinkLocal',str) == 'LinkLocal':
result = 'LinkLocal'
elif re.sub(r'^FEC0::/10$|^FE[CDEF]{1}[0-9A-F]{1}(:[0-9A-F]{4}){6}:[0-9A-F]{4}$', r'SiteLocal',str) == 'SiteLocal':
result = 'SiteLocal'
elif re.sub(r'^FF00::/10$|^FF[0-9A-F]{2}(:[0-9A-F]{4}){6}:[0-9A-F]{4}$', r'Multicast', str) == 'Multicast':
result = 'Multicast'
elif re.sub(r'^([0-9A-F]{4}:){7}[0-9A-F]{4}$', r'Globalcast', str) == 'Globalcast':
result = 'Globalcast'
else:
result = 'Error'
print(result)
regex(str)
上面這個寫法,用輸入流進行輸入、輸出,因為牛客網對輸入輸出有要求。
然后在終端運行文件(用了sys.stdin的輸入流,只能通過命令行來執行):
1.在命令行中打開父文件夾
2.`python 文件名.py ` 運行pthon文件
3.輸入參數(本例子的參數是字符串)
以下是python輸入輸出說明的樣例: