首页
IT
登录
6mi
u
盘
搜
搜 索
IT
HDU 2577(dp46)
HDU 2577(dp46)
xiaoxiao
2025-06-01
30
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using
namespace
std
;
int
dp[
105
][
2
];
char
str[
105
];
int
main() {
int
num;
int
i;
scanf
(
"%d\n"
,&num);
while
(num--) { gets(str);
int
len=
strlen
(str);
memset
(dp,
0
,
sizeof
(dp)); dp[
0
][
1
]=
1
;
for
(i=
0
;i<len;i++) {
if
(str[i]>=
'a'
&&str[i]<=
'z'
) { dp[i+
1
][
0
]=min(dp[i][
0
]+
1
,dp[i][
1
]+
2
); dp[i+
1
][
1
]=min(dp[i][
0
]+
2
,dp[i][
1
]+
2
); }
else
{ dp[i+
1
][
0
]=min(dp[i][
0
]+
2
,dp[i][
1
]+
2
); dp[i+
1
][
1
]=min(dp[i][
0
]+
2
,dp[i][
1
]+
1
); } }
printf
(
"%d\n"
,min(dp[len][
0
],dp[len][
1
]+
1
)); }
return
0
; }
转载请注明原文地址: https://ju.6miu.com/read-1299473.html
最新回复
(
0
)