#P13992. 【MX-X19-T1】「FeOI Round 4.5」五字神人
【MX-X19-T1】「FeOI Round 4.5」五字神人
Description
A string consisting only of uppercase and lowercase English letters is called a "Five-Letter Deity" if and only if the total length of the string is or the number of uppercase letters is .
mxzhn gives you a non-empty string (containing only uppercase and lowercase English letters). You need to transform this string into a "Five-Letter Deity" using any number of the following three operations:
- If the string is non-empty, delete any one character.
- Modify any one character to an uppercase or lowercase letter.
- Append a lowercase letter to the end of the string.
Find the minimum number of operations required.
Input Format
The input contains multiple test cases.
The first line contains an integer , indicating the number of test cases. For each test case:
- One line, a non-empty string . It is guaranteed that contains only uppercase and lowercase English letters.
Output Format
For each test case, output one line containing an integer, which is the corresponding minimum number of operations.
3
mxzhn
tymxzhn
vegetableking
0
2
5
9
TYmxzhn
VeGeTaBleKing
YuanShenQiDong
DuDuDu
NotCleverSYL
JianYu
wwwwwza
Anemones
wmrqwq
2
0
1
1
0
1
2
3
1
Hint
【Sample Explanation #1】
For the three strings:
mxzhnalready satisfies the requirement without any changes.tymxzhncan be transformed intomxzhnby deleting the first two characters.vegetablekingcan be changed toVeGeTaBleKingwithin five operations.
It can be proved that the number of operations is minimal for each. Note that there may be multiple ways to achieve the same result with the same number of operations.
【Data Range】
Let denote the length of string .
The test cases are not equally weighted. See the score column for details.
| Test Case ID | Special Condition | Score | |
|---|---|---|---|
| None | |||
| The string contains only uppercase letters | |||
| The string contains only lowercase letters | |||
| None | |||
For all test cases, , , and the string contains only uppercase and lowercase English letters.
Translated by DeepSeek V3.1
京公网安备 11011102002149号