现在的位置: 首页 > 综合 > 正文

CF – 408 – B. Garland

2019年08月30日 ⁄ 综合 ⁄ 共 757字 ⁄ 字号 评论关闭

题意:给两个由小写字母组成的字符串,长度分别为n,m (1 <= n, m <= 1000),代表有n张纸,一个要做成的m的花环,每个字符串的每个不一样的小写字母代表一种颜色,问最多能用多少张纸做成符合要求的花环,纸可以裁剪。

题目链接:http://codeforces.com/problemset/problem/408/B

——>>起床秒一题。。

统计字母出现的次数。。扫描26个字母的出现次数,判断一下。。

#include <cstdio>
#include <cstring>

using namespace std;

const int maxn = 1000 + 10;
const int al_maxn = 26 + 5;

char s[maxn], t[maxn];
int scnt[al_maxn], tcnt[al_maxn];

int main()
{
    while(scanf("%s%s", s, t) == 2) {
        int slen = strlen(s);
        int tlen = strlen(t);
        memset(scnt, 0, sizeof(scnt));
        memset(tcnt, 0, sizeof(tcnt));
        for(int i = 0; i < slen; i++) scnt[s[i]-'a']++;
        for(int i = 0; i < tlen; i++) tcnt[t[i]-'a']++;
        int Max_area = 0;
        bool ok = true;
        for(int i = 0; i < 26; i++) {
            if(!tcnt[i]) continue;
            if(!scnt[i] && tcnt[i]) ok = false;
            if(scnt[i] > tcnt[i]) Max_area += tcnt[i];
            else Max_area += scnt[i];
        }
        ok ? printf("%d\n", Max_area) : puts("-1");
    }
    return 0;
}

抱歉!评论已关闭.