国庆练习5

Phone Numbers CF 1060A

Description

Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.

For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.

You have n n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.

Input

The first line contains an integer nn — the number of cards with digits that you have (1n1001≤n≤100).

The second line contains a string of nn digits (characters "0", "1", ..., "9") s1,s2,,sns1,s2,…,sn. The string will not contain any other characters, such as leading or trailing spaces.

Output

If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.

Sample Input

Input
11 
00000000008
Output
1
Input
22 
0011223344556677889988
Output
2
Input
11 
31415926535
Output
0

Hint

In the first example, one phone number, "8000000000", can be made from these cards.

In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".

In the third example you can't make any phone number from the given cards.

题目意思:给你长度为n个数字字符串,求出能够组合成多少个电话号码。每一个数字都只能使用一次,电话号必须是8开头,长度为11。

解题思路:数字字符串的长度和8的数量决定了能构成的电话号码的个数。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<map>
 4 #include<algorithm>
 5 using namespace std;
 6 char s[110];
 7 int main()
 8 {
 9     int n,i,counts,a,ans;
10     scanf("%d",&n);
11     counts=0;
12     a=0;
13     getchar();
14     gets(s);
15     for(i=0;i<n;i++)
16     {
17         if(s[i]=='8')
18         {
19             counts++;
20         }
21     }
22     a=n/11;
23     ans=min(a,counts);
24     printf("%d\n",ans);
25     return 0;
26 }

猜你喜欢

转载自www.cnblogs.com/wkfvawl/p/9746955.html