Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #define int long long
- using namespace std;
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int test_cases;
- cin >> test_cases;
- while(test_cases--) {
- int str_len, num_positions;
- cin >> str_len >> num_positions;
- string input_str, replacement_chars;
- cin >> input_str;
- vector<int> positions(num_positions);
- vector<char> replacement_list(num_positions);
- for(int i = 0; i < num_positions; ++i) {
- cin >> positions[i];
- input_str[positions[i] - 1] = '*';
- }
- cin >> replacement_chars;
- for(int i = 0; i < num_positions; ++i) {
- replacement_list[i] = replacement_chars[i];
- }
- sort(replacement_list.begin(), replacement_list.end());
- int idx = 0;
- for(int i = 0; i < str_len; ++i) {
- if(input_str[i] == '*') {
- input_str[i] = replacement_list[idx];
- ++idx;
- }
- }
- cout << input_str << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement