杭电ACM HDU 2577 How to Type

阅读 63

2023-08-21


How to Type

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2528    Accepted Submission(s): 1179


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


Hint



 


Author


Dellenge



 


Source


HDU 2009-5 Programming Contest



 


Recommend


lcy



 

虽然是水题,但是我交了n多次都WA,就在我要放弃的时候竟然AC了,还是细节注意的不够

 

#include <stdio.h>
#include <string.h>
int isA(char c){
    return c>='A'&&c<='Z';
}
int main(){
    int n,len,c;
    int i,j;
    char s[105];
    int caplock;
    scanf("%d",&n);
    while(n--){
        scanf("%s",s);
        c=len=strlen(s);
        caplock=0;
        for(i=0;i<len;i++){
            int t=isA(s[i]);
            for(j=i+1;j<len;j++){
                if(t!=isA(s[j]))break;
            }
            if(t==1&&caplock==0&&j-i<2)//只有一个大写字母,Cap键没有按下
                c++;//按shift键
            else if(t==1&&caplock==0&&j-i>=2)//有多于1个大写字母,Cap键没有按下
                c++,caplock=1;//按下Cap键
            else if(t==0&&caplock==1&&j-i<2&&j==len)//结尾有一个小写字母,Cap已经按下
                c++,caplock=0;//按下Cap键
            else if(t==0&&caplock==1&&j-i<2)//Cap已经按下,出现一个小写字母
                c++;//按shift键
            else if(t==0&&caplock==1&&j-i>=2)//Cap已经按下,出现多个小写字母
                c++,caplock=0;//按下Cap键
            i=j-1;
        }
        if(caplock)c++;
        printf("%d\n",c);
    }
}

 

 

 

精彩评论(0)

0 0 举报