HDU2577HowtoType (analog, DP)

Source: Internet
Author: User
A string of characters (consisting of uppercase and lowercase letters) when the input process of the simulated keyboard starts to be in lowercase, the input is required to be completed and the input is also in lowercase. the minimum number of buttons is calculated. I directly simulate the input. each character is indicated by the flag record the status 1 of the Capslock key. 0 indicates lowercase plu indicates the number of additional buttons. when flag = 1 and t lowercase letters are entered

The meaning of the question gives you a string of characters (consisting of upper-case letters and lower-case letters). the input process of the simulated keyboard starts with the lower-case state and requires that the input be completed or the lower-case state. The minimum number of buttons is required.

I directly simulate the input. each character uses a flag to record the status of the Capslock key. 1 indicates the upper-case status. 0 indicates the lower-case status. plu indicates the number of additional buttons.

When flag = 1 and t lowercase letters are to be entered next, it is easy to know that only t = 1 is the number of times that the shift key is used to enter the key is the same as the number of times that the Capslock key is used to input a shift is shift + a = 2 when capslock is capslock + a = 2 t> = 2, shift must be more than capslock, for example, input AB shift + a + shift + B = 4 capslock + a + B = 3. so if only one character is in a different status from capslock, shift and plu plus one. Otherwise, the capslock status is changed to plu plus one.

However, if there is only one lower-case letter at the end and the flag is 1, capslock should also be used. because the input should be switched to lower-case, shift should be used, and capslock should be clicked.

#include
 
  #include
  
   #include
   
    using namespace std;const int N = 105;int main(){    char s[N]; int cas, t;    scanf ("%d", &cas);    while (cas--)    {        scanf ("%s", s + 1);        int l = strlen (s + 1), plu = 0, flag = 0;        for (int i = 1; i <= l; ++i)        {            t = 0;            if (flag) while (islower (s[i])) ++t, ++i;            else      while (isupper (s[i])) ++t, ++i;            if (t > 1||(i == l + 1 && islower (s[l]) && t == 1))                flag = !flag, ++plu, --i;            else if (t == 1)                ++plu, --i;        }        if (flag) ++plu;        printf ("%d\n", l + plu);    }    return 0;}
   
  
 

How to TypeProblem DescriptionPirates 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.
InputThe 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 mo st 100.
OutputFor each test case, you must output the smallest times of typing the key to finish typing this string.
Sample Input
3PiratesHDUacmHDUACM
 
Sample Output
888HintThe 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 
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.