How to Type

穿精又带淫゛_ 提交于 2020-02-27 06:07:00

Problem Description

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

3
Pirates
HDUacm
HDUACM

Sample Output

8
8
8

 

 1 #include <cstdio>
 2 #include <string>
 3 #include <string>
 4 #include <iostream>
 5 using namespace std;
 6 
 7 int on[105],off[105];
 8 
 9 int main()
10 {
11     string s;
12     int t;
13     cin>>t;
14     while(t--)
15     {
16         cin>>s;
17         on[0]=1,off[0]=0;
18         for(int i=0; i<s.size(); i++)
19         {
20             if(s[i]<'a')
21             {
22                 on[i+1]=min(on[i]+1,off[i]+2);
23                 off[i+1]=min(on[i]+2,off[i]+2);
24             }
25             else
26             {
27                 on[i+1]=min(on[i]+2,off[i]+2);
28                 off[i+1]=min(on[i]+2,off[i]+1);
29             }
30             on[s.size()]++;
31         }
32         cout<<min(on[s.size()],off[s.size()])<<endl;
33     }
34 
35     return 0;
36 }
View Code

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!