标签:find ping eof 状态 case which class sam --
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6787 Accepted Submission(s):
3057
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int dp[105][2];
char s[105];
int solve()
{
int i,j,k,sz=strlen(s);
memset(dp,inf,sizeof(dp));
if(islower(s[0])){
dp[0][0]=1;
dp[0][1]=2;
}
else{
dp[0][0]=2;
dp[0][1]=2;
}
for(i=1;i<sz;++i){
if(islower(s[i])){
dp[i][0]=min(dp[i-1][1]+2,dp[i-1][0]+1);
dp[i][1]=min(dp[i-1][1]+2,dp[i-1][0]+2);
}
else{ //da xie
dp[i][0]=min(dp[i-1][1]+2,dp[i-1][0]+2);
dp[i][1]=min(dp[i-1][1]+1,dp[i-1][0]+2);
}
}
return min(dp[sz-1][0],dp[sz-1][1]+1);
}
int main()
{
int t,n,m,i,j;
cin>>t;
while(t--){cin>>s;
cout<<solve()<<endl;
}
return 0;
}
标签:find ping eof 状态 case which class sam --
原文地址:http://www.cnblogs.com/zzqc/p/6980397.html