• 统计字符的个数,能够组成几个acmicpc


    Problem F. String

    Input file:                  standard input

    Output file:               standard output

    Time limit:                1 seconds Memory limit:          128 megabytes

    大家都知道马大佬很皮

    马大佬很喜欢 ICPC,马大佬现在手里有 n 块积木,每一个积木是 a 到 z,26 个英文字母 中的一个,现在马大佬想用这些积木组成尽可能多的  acmicpc,问你能组成多少个

    Input

    输入第一行一个整数 T,代表接下来有 T 组测试数据 接下来 T 行,每一行先输入一个整数 n,代表积木的数量

    接下来输入一个长度为 n 的字符串,代表每一个积木的英文字母 数据保证只有小写字母

    1 <= T <= 10,1 <= n <= 100000

    Output

    对于每一组测试数据,输出对应答案

    Example

     

    standard input

    standard output

    1

    8

    aacmicpc

    1

    #include<iostream>
    #include<cmath>
    #include<cstring>
    #define N 100000
    using namespace std;
    
    int main()
    {
        char str[N];
        int t;
        cin >> t;
        while(t--)
        {
            int n;
            int num;
            int a = 0,c = 0,i = 0,m = 0,p = 0,flag = 0;
            cin >> n >> str;
            for(int j = 0;j < n;j++)
            {
                if(str[j] == 'a')
                    a++;
                if(str[j] == 'c')
                    c++;
                if(str[j] == 'i')
                    i++; 
                if(str[j] == 'm')
                    m++;
                if(str[j] == 'p')
                    p++;    
            }
            num = min(a,i);
            num = min(num,m);
            num = min(num,p);
            num = min(num,c/3);
    //        cout << a << " " << c << " " << i << " " << m << " " << p << endl;
            cout << num << endl;
        }
        return 0;
    }
  • 相关阅读:
    小三学算术
    The Balance
    扫描线
    2019牛客暑期多校训练营(第九场)
    后缀数组
    Manacher
    局部变量和全局变量的区别
    2386:Lake Counting-poj
    简单背包问题(0032)-swust oj
    编程中易犯错误集锦-持续更新。。。。。
  • 原文地址:https://www.cnblogs.com/biaobiao88/p/11667933.html
Copyright © 2020-2023  润新知