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<stdio.h> #include<string.h> int main() { int t,sum,ans,da,i; char a[2050]; scanf("%d",&t); while(t--) { scanf("%s",a); sum=ans=0; da=0; for(i=0;a[i]!=0;i++) { if(a[i]>='A'&&a[i]<='Z'&&a[i+1]>='A'&&a[i+1]<='Z'&&da==0)//如果连续两个大写 就转成大写的 { da=1; ans++; } if(a[i]>='a'&&a[i]<='z'&&(a[i+1]>='a'&&a[i+1]<='z'||a[i+1]==0)&&da==1)//连续两个小写的就转成大写的 //注意:如果已经是最后一个的话,就要转换成小写,这样最后可以少一步转换回小写的操作; { da=0; ans++; } if(a[i]>='A'&&a[i]<='Z') { if(da==0) ans+=2; else ans++; } else if(a[i]>='a'&&a[i]<='z') { if(da==0) ans++; else ans+=2; } } if(da) { ans++; } printf("%d\n",ans); } return 0; }
hdu 2577 How to Type 如何保证英文输入状态下,可以按最小次数来完成输入
原文地址:http://blog.csdn.net/u013532224/article/details/39231739