题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
# !/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'tianyi' __date__ = '2024/3/19 21:31 ' __file__ = 'HW_HJ74.py' #转换字符串成命令行参数 String = input().rstrip() Command_list = [] Temp = "" n=0 for i in range(len(String)): if String[i] == "\"": if n == 0: n=1 continue elif n == 1: Command_list.append(Temp) Temp = "" n=2 continue elif String[i] == " ": if n == 1: Temp += String[i] elif n == 2: n=0 continue else: Command_list.append(Temp) if Temp != "" else None Temp = "" else: Temp += String[i] if Temp != "": if i == len(String)-1: Command_list.append(Temp) Temp = "" print(len(Command_list)) for i in Command_list: print(i)
个人感觉考虑最难点是“sfd dafd” 中间 包含的情况