codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

180C.md (1508B)


      1 Source: https://codeforces.com/problemset/problem/180/C
      2 
      3 C. Letter
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
     22 
     23 Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
     24 
     25 To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
     26 
     27 Input
     28 
     29 The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
     30 
     31 Output
     32 
     33 Print a single number — the least number of actions needed to make the message fancy.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 PRuvetSTAaYA
     41 ```
     42 
     43 Output
     44 
     45 ```
     46 5
     47 ```
     48 
     49 Input
     50 
     51 ```
     52 OYPROSTIYAOPECHATALSYAPRIVETSTASYA
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 0
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 helloworld
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 0
     71 ```