codeforces 1060a(思维水题)

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 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
n — the number of cards with digits that you have (1≤n≤100).

The second line contains a string of n digits (characters “0”, “1”, …, “9”) s1,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.

Examples
inputCopy
11
00000000008
outputCopy
1
inputCopy
22
0011223344556677889988
outputCopy
2
inputCopy
11
31415926535
outputCopy
0
Note
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.
完全就是一道思维水题,想明白就好了。。有可能有5个8,但是可能就只能组成两个电话号码。所以就只能是2。但是呢,如果可以组成5组电话号码,不过只有2个8,那也只能组成2个。找这之间的两者的最小值就好了。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int n;
char s[101];

int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int count=0;
		scanf("%s",s); 
		for(int i=0;i<n;i++)
		{
			if(s[i]=='8') count++;
		}
		int ans=n/11;
		cout<<min(count,ans)<<endl; 
	}
	return 0;
}

多锻炼点思维,对a题有好处的。
努力加油a啊,(o)/~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值