当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 统计字符的个数,能够组成几个acmicpc

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

2019年10月14日  | 移动技术网IT编程  | 我要评论

前列腺炎囊肿,兽交母羊,黑铁酒杯

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;
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网