请输入一段字符串(由空格、字母和数字几种组成,保证开头不为空格),当输入的字符串为"stop"时结束输入。程序会输出这些字符串的长度和,并输出最长字符串内容(如果有多个输出最先出现的那个字符串)。
时间: 2023-06-27 20:06:24 浏览: 69
输入一串字符和输出
```python
max_len = 0
max_str = ''
total_len = 0
while True:
s = input()
if s == 'stop':
break
length = len(s)
total_len += length
if length > max_len:
max_len = length
max_str = s
print('Total length:', total_len)
print('Max length:', max_len)
print('Max string:', max_str)
```
输入示例:
```
hello world
python is cool
this is a test
stop
```
输出示例:
```
Total length: 43
Max length: 16
Max string: python is cool
```
阅读全文