用dp(i, 0)表示关掉CapsLK情况下输入第i-1个字母最少按键数,dp(i, 1)表示开启CapsLK情况下输入第i-1个字母的最少按键数
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
int dp[110][2];
int main()
{
// freopen("in.txt", "r", stdin);
int n;
cin >> n;
while(n--)
{
string s;
cin >> s;
dp[0][0] = 0;
dp[0][1] = 1;
for(int i = 1; i <= s.size(); i++)
{
if(s[i-1] <= 'Z')
{
dp[i][0] = min(dp[i-1][0] + 2, dp[i-1][1] + 2);
dp[i][1] = min(dp[i-1][0] + 2, dp[i-1][1] + 1);
}
else{
dp[i][0] = min(dp[i-1][0] + 1, dp[i-1][1] + 2);
dp[i][1] = min(dp[i-1][0] + 2, dp[i-1][1] + 2);
}
}
cout << dp[s.size()][0] << endl;
}
return 0;
}