文章目录
一、题目
输入格式:
输出格式:
输入样例:
输出样例:
二、方法1
1、思路
本题运用了正则表达式:
- 除去首尾的空格;
- 除去多余空格;
- 除去标点符号前的空格;
- 将 ? 替换为 !;
- 把除 I 以外的所以字符变为小写;
- 先分别存放 can I,could I 中的 can,could,再添加 you(将 I,me改为 you)。
2、代码
import re
for i in range(int(input())):
str1=input()
print(str1)
print('AI: ', end='')
str1=str1.strip()
str1 = re.sub(r'(\s+)', ' ', str1)
str3 = re.compile(r' +(\W)')
str1 = str3.sub(r"\1", str1)
str1 = re.sub('\?', '!', str1)
for j in str1:
if j != 'I':
str1 = str1.replace(j, j.lower())
str1 = re.sub(r'(\bcan you\b)', '_I can', str1)
str1 = re.sub(r'(\bcould you\b)', '_I could', str1)
str1 = re.sub(r'(\bI\b)', 'you', str1)
str1 = re.sub(r'(\bme\b)', 'you', str1)
str1 = re.sub(r'(\b_I\b)', 'I', str1)
print(str1)