ACM 训练日志记录 · 思考 · 成长 提交 / 修改记录
郭一鸣 / 题目列表训练档案
导出

2257A Codeforces Round 1117 (Div. 2)

来源:Codeforces ★ 800

本题活力0.19按难度、完成结果与训练证据估算

算法如山行则将至

题目描述

判断给定的 m 个缩写是否都能由已有单词首字母组合生成。

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        bool al[26]={false};
        string s;
        for(int i=1;i<=n;i++)
        {
            cin>>s;
            al[s[0]-'a']=true;
        }
        bool flag=true;
        for(int i=1;i<=m;i++)
        {
            cin>>s;
            for(int j=0;j<s.length();j++)
            {
                if(al[s[j]-'A']==false)
                {
                    flag=false;
                }
            }
        }
        if(flag)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}