How to Type (字符大小写转换)
来源:互联网 发布:js 键值对动态赋值 编辑:程序博客网 时间:2024/06/11 00:02
How to Type(字符大小写转换)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 Sample Output Hint
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.
3PiratesHDUacmHDUACM
888
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 8The 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;}
阅读全文
1 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)
- 状态机的伪Java代码实现与一点想法
- STM32F103mini教程学习总结与心得(二)---->串口通信
- Tomcat使用总结
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- 十三、断路器-Hystrix 的隔离策略
- How to Type (字符大小写转换)
- 类型萃取
- Servlet学习
- 多态性和虚函数
- Linux文件的压缩与解压缩
- 模糊查询
- Windows下使用Sublime Text配置C++编译环境
- [BZOJ 3330] 分数 三分法+精度优化
- 1059. Prime Factors (25)