3 Pirates HDUacm HDUACM
8 8 8HintThe string “Pirates”, can type this way, Shift, p, i, r, a, t, e, s, the answer is 8. The string “HDUacm”, can type this way, Caps lock, h, d, u, Caps lock, a, c, m, the answer is 8 The string "HDUACM", can type this way Caps lock h, d, u, a, c, m, Caps lock, the answer is 8
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int const MAX = 105; char s[MAX]; int dp[MAX][2]; bool judge(char ch) { if(ch >= 'A' && ch <= 'Z') return true; return false; } int main() { int T; scanf("%d", &T); while(T--) { scanf("%s", s + 1); int len = strlen(s + 1); memset(dp,0, sizeof(dp)); dp[0][1] = 1; for(int i = 1; i <= len; i++) { if(judge(s[i])) { dp[i][1] = min(dp[i - 1][1] + 1, dp[i - 1][0] + 2); dp[i][0] = min(dp[i - 1][0] + 2, dp[i - 1][1] + 2); } else { dp[i][1] = dp[i - 1][1] + 2; dp[i][0] = dp[i - 1][0] + 1; } } printf("%d\n", min(dp[len][0], dp[len][1] + 1)); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/tc_to_top/article/details/46854871