• 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 HashMap 和 ConcurrentHashMap
    递归算法应用
    二叉树基础知识
    自动删除qq空间说说
    移动APP测试的22条军规--笔记
    SQL Server数据库状态监控
    SqlSugar-事务操作
    详解第一范式、第二范式、第三范式、BCNF范式
    SQL 日期
    2019年世界各国gdp排名对比
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4917884.html
Copyright © 2020-2023  润新知