cf——B. Garland

Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter.

The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.

Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​m pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.

Input

The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.

The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.

Output

Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.

原来第二个里面不能有第一个里面没有的字符

如果有的话,输出-1

Sample test(s)
input
aaabbac
aabbccac
output
6
input
a
z
output
-1
Note

In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color aand cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.

In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color z.

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
int main()
{
    string s,str;
    map<char,int>Map1;
    cin>>s;
    cin>>str;
    int sum=0;
    for(int i=0;i<s.size();i++)
    {
        Map1[s[i]]++;
    }
    for(int i=0;i<str.size();i++)
    {
        if(Map1[str[i]]==0)
        {
            cout<<"-1"<<endl;
            return 0;
        }
    }
    for(int i=0;i<str.size();i++)
    {
        if(Map1[str[i]]!=0)
        {
            sum++;
            Map1[str[i]]--;
        }
    }
    if(sum==0)
    cout<<"-1"<<endl;
    else
    cout<<sum<<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值