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);
    }
  • 相关阅读:
    工具链中 Binutils的内容
    Qt 4.5 新功能逐一看 – 性能优化
    qt 打不开 用于触摸屏校准的文件
    Unicode 编码范围
    Android OpenGL ES 分析与实践
    Armlinux GCC 交叉编译工具
    二维矢量图形算法加速标准 OpenVG
    电路和程序一样,不是设计出来的,是调出来的
    电子元件又一话电容篇
    TVS管
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4917884.html
Copyright © 2011-2022 走看看