CF180C.Letter

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.

Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.

To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.

帕特里克刚刚写完一条给他的心上人斯塔西的信息,却突然发现这条信息看起来不够“华丽”。由于帕特里克在书写时十分紧张,信息中有些字母是小写的,而有些则是大写的。

帕特里克认为,一条信息是“华丽的”,当且仅当任意一个大写字母都位于任意一个小写字母的左侧。换言之,该规则描述的是这样的字符串:先出现零个或多个大写字母,然后(在其右侧)出现零个或多个小写字母。

为了使信息变得“华丽”,帕特里克可以擦除某个字母,并在同一位置以相反大小写重新插入该字母(即:将大写字母替换为对应的小写字母,或将小写字母替换为对应的大写字母)。帕特里克开始思考这样一个问题:最少需要多少次操作才能使该信息变得“华丽”? 其中,将信息中某字母的大小写进行切换计为一次操作。帕特里克不能执行任何其他操作。

输入格式

The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.

输入仅包含一行,为一个非空字符串,由大小写字母组成。字符串的长度不超过 10510^5。

输出格式

Print a single number — the least number of actions needed to make the message fancy.

输出一个整数——使消息变得“花哨”所需的最少操作次数。

输入输出样例

  • 输入#1

    PRuvetSTAaYA

    输出#1

    5
  • 输入#2

    OYPROSTIYAOPECHATALSYAPRIVETSTASYA

    输出#2

    0
  • 输入#3

    helloworld

    输出#3

    0

输入解题思路,AI测评打分。不知道怎么写?

首页