Problem Generator

Vlad is planning to hold mm rounds next month. Each round should contain one problem of difficulty levels 'A', 'B', 'C', 'D', 'E', 'F', and 'G'.

Vlad already has a bank of nn problems, where the ii-th problem has a difficulty level of aiai​. There may not be enough of these problems, so he may have to come up with a few more problems.

Vlad wants to come up with as few problems as possible, so he asks you to find the minimum number of problems he needs to come up with in order to hold mm rounds.

For example, if m=1m=1, n=10n=10, a=a= 'BGECDCBDED', then he needs to come up with two problems: one of difficulty level 'A' and one of difficulty level 'F'.

Input

The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

The first line of each test case contains two integers nn and mm (1≤n≤501≤n≤50, 1≤m≤51≤m≤5) — the number of problems in the bank and the number of upcoming rounds, respectively.

The second line of each test case contains a string aa of nn characters from 'A' to 'G' — the difficulties of the problems in the bank.

Output

For each test case, output a single integer — the minimum number of problems that need to come up with to hold mm rounds.

Examples

InputcopyOutputcopy
3
10 1
BGECDCBDED
10 2
BGECDCBDED
9 1
BBCDEFFGG
2
5
1

思路:

本题是求从A~G为一个循环,若组成m个环,最少需要补充多少字母。

想要得到一个循环,则需要A~G各一个,故只需要统计每个字母的数量就行,若一个字母的数量少于m个,则答案增加m减去该字母的数量

代码

#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >>t;
    while(t--)
    {
        int a[10] = {0};
        int n,m;
        cin >>n>>m;
        for(int i=0;i<n;i++)
        {
            char c;
            cin >>c;
            if(c == 'A') a[0]++;
            else if(c == 'B') a[1]++;
            else if(c == 'C') a[2]++;
            else if(c == 'D') a[3]++;
            else if(c == 'E') a[4]++;
            else if(c == 'F') a[5]++;
            else if(c == 'G') a[6]++;
        }
        int ans = 0;
        for(int i=0;i<7;i++)
        {
            // cout <<a[i]<<" ";
            if(a[i] < m) ans += m - a[i];
        }
        // cout <<endl;
        cout <<ans<<endl;
    }
    return 0;
}

本题知道如何统计数字的数量就可以解决

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值