标签:
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
两个状态,大写锁定开,大写锁定关。然后推后一个状态取最小值即可。
因为这个最后她还要把大写锁定给关了,那就需要最后再加一取下大小。
ac代码
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> #define min(a,b) (a>b?b:a) char s[110]; int dp[2][110]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%s",s); int len=strlen(s),i; if(isupper(s[0])) { dp[0][0]=2; dp[1][0]=2; } else { dp[0][0]=1; dp[1][0]=2; } for(i=1;i<len;i++) { if(isupper(s[i])) { dp[0][i]=min(dp[1][i-1]+2,dp[0][i-1]+2); dp[1][i]=min(dp[0][i-1]+2,dp[1][i-1]+1); } else { dp[0][i]=min(dp[1][i-1]+2,dp[0][i-1]+1); dp[1][i]=min(dp[0][i-1]+2,dp[1][i-1]+2); } } printf("%d\n",min(dp[0][len-1],dp[1][len-1]+1)); } }
标签:
原文地址:http://blog.csdn.net/yu_ch_sh/article/details/45697281