Codeforces Round 923 (Div. 3)

目录

A. Make it White

Problem - A - Codeforces

B. Following the String

Problem - B - Codeforces


A. Make it White

Problem - A - Codeforces

思路:第一个B的下标减去最后一个B的下标+1

完整代码:

#include 
#define int long long
signed main() {
    int t;
    std::cin >> t;
    while (t--) {
        int n;
        std::cin >> n;
        std::string s;
        std::cin >> s;
        s = " " + s;
        int ans = 0;
        int minn = 999, maxx = -9999;
        for (int i = 1; i <= n; i++) {
            if (s[i] == 'B') {
                minn = std::min(minn, i);
                maxx = std::max(maxx, i);
            }
        }
        std::cout << maxx - minn + 1 << "\n";
    }
    return 0;
}

B. Following the String

Problem - B - Codeforces

思路:暴力+模拟

完整代码:

#include 
#define int long long
signed main() {
    int t;
    std::cin >> t;
    while (t--) {
        int n;
        std::cin >> n;
        std::string s;
        std::map mp;
        for (int i = 0; i < n; i++) {
            int x;
            std::cin >> x;
            char ch = 'a';
            for (int j = 0; j < 26; j++) {
                if (mp[ch] == x) {
                    s += ch;
                    mp[ch]++;
                    break;
                }
                ch++;
            }
        }
        std::cout << s << "\n";
    }
    return 0;
}

你可能感兴趣的:(寒假集训,寒假算法,CF,算法,数据结构,c++,c语言)