列表

详情


NC25072. [USACO 2007 Ope l]Camel Case Variables

描述

Bessie has been programming in Java lately and has been contemplating variable names known as "camel case" variables. You might have seen these; each one contains several regular words but words after the first one are capitalized. Thus, a variable that contains the "number of cows" is written "numberOfCows".
As usual, Bessie's mind is wandering. 'What would the variables look like as each capital letter is removed?' she wondered.
Write a program that reads in a single "camel case" word (2 <= length <= 80) and successively removes the capitalized variable that appears latest in normal english alphabetical order. It is
promised that all capital letters are unique within a given variable name and that at least one capital letter iexsts.
Here's an example that shows the stages of transforming the variable
'theRainInSpainFallsMainlyOnThePlain':
theRainInSpainFallsMainlyOnhePlain <-- remove T
theRainInpainFallsMainlyOnhePlain <-- remove S
theainInpainFallsMainlyOnhePlain <-- remove R
theainInpainFallsMainlyOnhelain <-- remove P
theainInpainFallsMainlynhelain <-- remove O
theainInpainFallsainlynhelain <-- remove M
theainnpainFallsainlynhelain <-- remove I
theainnpainallsainlynhelain <-- remove F

输入描述

Line 1: A camel-case variable name containing no blanks

输出描述

Lines 1..??: Each line shows the original camel case variable with one more upper-case letter removed

示例1

输入:

theRainInSpainFallsMainlyOnThePlain

输出:

theRainInSpainFallsMainlyOnhePlain
theRainInpainFallsMainlyOnhePlain
theainInpainFallsMainlyOnhePlain
theainInpainFallsMainlyOnhelain
theainInpainFallsMainlynhelain
theainInpainFallsainlynhelain
theainnpainFallsainlynhelain
theainnpainallsainlynhelain

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Python3 解法, 执行用时: 41ms, 内存消耗: 4600K, 提交时间: 2023-08-19 14:59:48

s = input().strip()
arr =[c for c in s if c.isupper()]
arr.sort(reverse=True)
for c in arr:
    s = s.replace(c, '')
    print(s)

上一题