Codeforces Round #659 (Div. 2) A. Common Prefixes

题目链接:https://codeforces.com/contest/1384/problem/A

题意

构造 $n+1$ 个字符串,使得 $n$ 对相邻字符串的相同前缀长度对应于数组 $a$ 。

题解

构造一个足够长的字符串,每次反转前缀不同处的字符即可。

代码

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; cin >> n;
    string s(200, 'a');
    cout << s << "
";
    for (int i = 0; i < n; ++i) {
        int j; cin >> j;
        s[j] = (s[j] == 'a' ? 'b' : 'a');
        cout << s << "
";
    }
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}
原文地址:https://www.cnblogs.com/Kanoon/p/13378844.html