B. Sheldon and Ice Pieces

194 篇文章 1 订阅
13 篇文章 0 订阅

链接:https://codeforces.com/problemset/problem/328/B

Do you remember how Kai constructed the word "eternity" using pieces of ice as components?

Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect "Digital Mimicry".

Sheldon favourite number is t. He wants to have as many instances of t as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once.

Input

The first line contains integer t (1 ≤ t ≤ 10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9.

Output

Print the required number of instances.

Examples

input

Copy

42
23454

output

Copy

2

input

Copy

169
12118999

output

Copy

1

Note

This problem contains very weak pretests.

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<queue>
#include<algorithm>
#include<cstdlib>
using namespace std;
long long t,g,r,n;
char a[1001];
int b[1001];
map<int,int>m,p;
int main()
{
	cin>>t;
	cin>>a;
	n=strlen(a);
	for(int i=0;i<n;i++)
    {
    	b[i+1]=a[i]-'0';
    	m[b[i+1]]++;
    }
    int min1=1000;
    while(t)
    {
    	int x=t%10;
    	t/=10;
    	p[x]++;
    }
    for(int i=0;i<=9;i++)
    {
    	if(p[i]!=0)
    	{
    		if(i==2||i==5)
			min1=min(min1,(m[2]+m[5])/(p[2]+p[5]));
			else if(i==9||i==6)
			min1=min(min1,(m[6]+m[9])/(p[6]+p[9]));
			else
    		min1=min(min1,m[i]/p[i]);
    	}
    }
    cout<<min1;
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值