How to Type---HDU 2577
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 HDUACMSample Output
8 8 8Hint
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int t,i,j,flag,sum;
char a[2][500];
scanf("%d",&t);
while(t--)
{
memset(a,1,sizeof(a));
scanf("%s",a[0]);
for(i=0; i<strlen(a[0]);)
{
if(a[0][i]>='A'&&a[0][i]<='Z')
{
j=i+1;
while(a[0][j]>='A'&&a[0][j]<='Z')
{
a[1][i]+=1;
j++;
}
i+=a[1][i];
}
if(a[0][i]>='a'&&a[0][i]<='z')
{
j=i+1;
while(a[0][j]>='a'&&a[0][j]<='z')
{
a[1][i]+=1;
j++;
}
i+=a[1][i];
}
}
sum=0;flag=0;
for(i=0; i<strlen(a[0]);)
{
if(a[0][i]>='A'&&a[0][i]<='Z')
{
if(a[1][i]>1)
{
if(flag==0)
{
flag=1;
sum=sum+a[1][i]+1;
}
else
{
sum+=a[1][i];
}
}
else
{
if(flag==0)
{
sum=sum+a[1][i]+1;
}
else
{
sum+=1;
}
}
i+=a[1][i];
}
if(a[0][i]>='a'&&a[0][i]<='z')
{
if(a[1][i]>1)
{
if(flag==1)
{
sum+=1;
flag=0;
sum+=a[1][i];
}
else
{
sum+=a[1][i];
}
}
else
{
if(flag==1)
{
if(i==strlen(a[0])-1)
{
sum+=2;
flag=0;
}
else
{
sum+=2;
}
}
else
{
sum+=1;
}
}
i+=a[1][i];
}
}
if(flag==1)
{
sum+=1;
}
printf("%d\n",sum);
}
return 0;
}