Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2), problem: (A) Phone Numbers

传送门(懒得截图了):http://codeforces.com/contest/1060/problem/A

        这个号码要求8开头,然后后面10个数字,注意到8可以在开头,也可以作为跟在其他8后的数字,那么答案就是8的个数和总个数除以11的最小值。

代码如下:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int read(){
    int f = 1, x = 0;char ch = getchar();
    while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
    return x * f;
}
int main(){
    int n,cnt1 = 0,cnt2 = 0;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '8') cnt1++;
        else cnt2++;
    }
    cout << min(cnt1,(cnt2+cnt1)/11) << endl;
    

猜你喜欢

转载自blog.csdn.net/CCCCTong/article/details/82942678