zoukankan      html  css  js  c++  java
  • Codeforces Round #116 (Div. 2, ACM-ICPC Rules) C. Letter 暴力

    C. Letter

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/180/problem/C

    Description

    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.

    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.

    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.

    Input

    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.

    Output

    Print a single number — the least number of actions needed to make the message fancy.

    Sample Input

    PRuvetSTAaYA

    Sample Output

    5

    HINT

    题意

    给你一个字符串,每次操作你可以将一个大写字母变成小写字母或者小写字母变成大写字母

    然后问你最少多少次操作,可以使得这个字符串变成,左边全是大写,右边全是小写字母的形式

    题解:

    直接暴力枚举有多少个大写字母就好了

    代码

    #include<iostream>
    #include<stdio.h>
    #include<cstring>
    using namespace std;
    
    #define maxn 100005
    char s[maxn];
    int low[maxn],high[maxn];
    int main()
    {
        scanf("%s",s+1);
        int len = strlen(s+1);
        for(int i=1;i<=len;i++)
        {
            low[i]=low[i-1];
            high[i]=high[i-1];
            if(s[i]<='z'&&s[i]>='a')
                low[i]++;
            else
                high[i]++;
        }
        int ans = 9999999;
        for(int i=0;i<=len;i++)
        {
            ans = min(ans,i-high[i]+(high[len]-high[i]));
        }
        printf("%d
    ",ans);
    }
  • 相关阅读:
    查看java程序中对象占用空间大小
    elasticsearch的基本了解
    kafka命令及启动
    屠龙之路_大杀技之倚天屠龙_TenthDay
    屠龙之路_坚持就是胜利_NinthDay
    屠龙之路_狭路相逢勇者胜_EighthDay
    屠龙之路_任生活如何虐你,屠龙之路还得继续_SeventhDay
    屠龙之路_假期罢工和公主私奔_SixthDay
    屠龙之路_击败DB小boss_FifthDay
    屠龙之路_转角遇到服务器大魔王_FourthDay
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4917884.html
Copyright © 2011-2022 走看看