zoukankan      html  css  js  c++  java
  • Gotta Catch Em' All!

    Gotta Catch Em' All!

    Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.

    Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur"(without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.

    Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?

    Note: uppercase and lowercase letters are considered different.

    Input

    Input contains a single line containing a string s (1??≤??|s|??≤??105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.

    The string s contains lowercase and uppercase English letters, i.e. .

    Output

    Output a single integer, the answer to the problem.

    Example

    Input
    Bulbbasaur
    Output
    1
    Input
    F
    Output
    0
    Input
    aBddulbasaurrgndgbualdBdsagaurrgndbb
    Output
    2


    一道很水的题,但是处理不好就很容易WA。。WA了6次。。。泪奔。。。。

    题意:给你一个字符串,让你判断里面有几个“Bulbasaur”,不要求顺序。
    这道题网上的解好像都是用一个数组存储每个字母出现的次数,然后出现最低的次数就是答案了。
    我用的方法是对字符串排序,并且对“Bulbasaur”排序,然后一个for循环找出有几个。
    代码如下:
    #include<iostream>
    #include<cstdio>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    char v[100000];
    int ans = 0;
    int main()
    {
        scanf("%s", v);
        int n = strlen(v);
        sort(v, v + n);
        char v1[12] = "Bulbasaur";
        sort(v1, v1 + 9);
        v1[9] = '';
        int j = 0;
        for (int i = 0; i < n;i++)
        {
            if (j == 8 && v[i] == v1[j])//这里要判断。。没处理好让我WA了3次
            {
                ans++;
                v[i] = '0';//这里又让我WA了3次。。。
                j = 0;
                i = 0;
            }
            if (v[i] == v1[j])
            {
                v[i] = '0';
                j++;
            }
        }
        printf("%d
    ", ans);
        return 0;
    }
    
    
     
    
    
    
    
  • 相关阅读:
    luoguP4336 [SHOI2016]黑暗前的幻想乡 容斥原理 + 矩阵树定理
    luoguP4208 [JSOI2008]最小生成树计数 矩阵树定理
    luoguP2303 [SDOI2012]Longge的问题 化式子
    poj1704 Georgia and Bob 博弈论
    poj3537 Crosses and Crosses 博弈论
    luoguP4783 [模板]矩阵求逆 线性代数
    luoguP5108 仰望半月的夜空 [官方?]题解 后缀数组 / 后缀树 / 后缀自动机 + 线段树 / st表 + 二分
    [Luogu5319][BJOI2019]奥术神杖(分数规划+AC自动机)
    Forethought Future Cup
    Codeforces Round 554 (Div.2)
  • 原文地址:https://www.cnblogs.com/Anony-WhiteLearner/p/6284542.html
Copyright ? 2011-2022 开发猿


http://www.vxiaotou.com