How to Type(字符大小写转换)
来源:互联网 发布:linux find size 编辑:程序博客网 时间:2024/06/05 02:25
How to Type(字符大小写转换)
Pirates have finished developing the typing software. He called Cathy to test his typing software. She is good at thinking. After testing for several days, she finds that if she types a string by some ways, she will type the key at least. But she has a bad habit that if the caps lock is on, she must turn off it, after she finishes typing. Now she wants to know the smallest times of typing the key to finish typing a string.
Input
The first line is an integer t (t<=100), which is the number of test case in the input file. For each test case, there is only one string which consists of lowercase letter and upper case letter. The length of the string is at most 100.
Output
For each test case, you must output the smallest times of typing the key to finish typing this string.
Sample Input
3PiratesHDUacmHDUACM
Sample Output
888
Hint
The 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<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){ int i,j,n,len; scanf("%d",&n); getchar(); while(n--) { char a[105]; int sum=0,x=0; gets(a); len=strlen(a); for(i=0;i<len;) { if(x==0&&a[i]>='A'&&a[i]<='Z'&&a[i+1]>='A'&&a[i+1]<='Z')//如果连续两个大写 就转成大写的; { x=1; sum++; } if(x==1&&a[i]>='a'&&a[i]<='z'&&(a[i+1]>='a'&&a[i+1]<='z'||a[i+1]==0))////连续两个小写的就转成小写的 //注意:如果已经是最后一个的话,就要转换成小写,这样最后可以少一步转换回小写的操作; { x=0; sum++; } if(a[i]>='a'&&a[i]<='z') { if(x==0) { sum++; i++; } else { sum+=2; i++; } } else { if(x==0) { sum+=2; i++; } else { sum++; i++; } } } if(x==1) sum++; printf("%d\n",sum); } return 0;}
- How to Type (字符大小写转换)
- How to Type(字符大小写转换)
- How to Type(DP)
- 字符的大小写转换
- 字符大小写转换
- vim 字符大小写转换
- 字符大小写转换
- 字符大小写转换
- 字符大小写转换...
- DELPHI字符大小写转换
- 字符的大小写转换!
- 字符大小写的转换
- 大小写字符转换
- 大小写字符转换
- mysql字符大小写转换
- 大小写字符的转换
- hdu 2577 How to Type(DP)
- hdu 2577 How to Type(DP)
- 为什么你的 Contributions 没有在你的 Profile 里显示?
- 模拟水题2
- Xamarin.Forms 用户界面——控件——主题——Dark Theme
- POJ
- mysql外键(Foreign Key)介绍和创建外键的方法
- How to Type(字符大小写转换)
- Spring的AOP:
- (淘宝无限适配)手机端rem布局详解
- android动态链接库(so文件)
- 电脑卡慢原因之磁盘占用100%
- String类
- JavaScript
- Xamarin.Fomrs 用户界面——控件——主题——自定义主题
- PAT-Deduplication on a Linked List