点击链接PTA-Python-AC全解汇总
题目:
缩写词是由一个短语中每个单词的第一个字母组成,均为大写。例如,CPU是短语“central processing unit”的缩写。
函数接口定义:
acronym(phrase);
phrase是短语参数,返回短语的缩写词
- 1
- 2
裁判测试程序样例:
/* 请在这里填写答案 */
phrase=input()
print(acronym(phrase))
- 1
- 2
- 3
输入样例:
central processing unit
- 1
输出样例:
CPU
- 1
我的代码:
def acronym(phrase):
res=""
for word in phrase.split():
res+=word[0].upper()
return res
- 1
- 2
- 3
- 4
- 5
评论记录:
回复评论: