B. Sheldon and Ice Pieces

链接: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;
}

 

全部评论

相关推荐

内向的柠檬精在研究求...:这不才9月吗,26到明年毕业前能一直找啊,能拿下提前批,转正的,offer打牌的都是有两把刷子的,为什么非要跟他们比。如果别人是9本硕+金牌+好几段大厂实习呢?如果别人是双非通天代呢?如果别人是速通哥呢?,做好自己就行了,我们做不到他们一样提前杀死比赛,但晚点到终点也没啥关系吧
双非应该如何逆袭?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务