hdu 2577

来源:互联网 发布:3344ff新域名 编辑:程序博客网 时间:2024/04/29 16:24

题意:问你打印这串字符串的最小步数,我们可以记录当时的Caps Lock键是否是打开,然后就是一步步的判断了

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){    int t;    scanf("%d",&t);    while (t--)    {        int on = 0;        int ans = 0;        char str[200];        scanf("%s",str);        int len = strlen(str);        for (int i = 0; i < len; ++i)        {            if (isupper(str[i]))            {                if (on == 1)                    ans += 1;                else                 {                    if (i == len - 1)                        ans += 2;                    else                     {                        if (!isupper(str[i+1]))   //之后是小写的,而且是关着的用shift                            ans += 2;                        else                         {                            on = 1;                            ans += 2;                        }                    }                }            }            else             {                if (on != 1)                    ans += 1;                else                {                    if (i == len - 1)                    {                        ans += 2;                        on = 0;                    }                    else                     {                        if (isupper(str[i+1]))                            ans += 2;                        else       // 之后是小写的,把大写键取消                        {                            ans += 2;                            on = 0;                        }                    }                }            }        }        if (on)            ans++;        printf("%d\n",ans);    }    return 0;}



原创粉丝点击