P10244 题解

贪心题。首先为了保证 aa 的字典序小,当 ai<cia_i<c_i 时要交换,ai>cia_i>c_i 时不交换。在 ai=cia_i=c_i 时,为了使 bb 的字典序尽可能小,则当 bi>dib_i>d_i 时不交换,否则交换。

代码

# include <bits/stdc++.h>
# define ffor(i,name) \
	for (auto i = name.begin (); i != name.end (); ++ i)
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int n;
string a, b, c, d;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> n >> a >> b >> c >> d;
	for (int i = 0; i < n; ++ i)
		if (a[i] > c[i])
			b[i] = d[i];
		else if (a[i] >= c[i])
			b[i] = min (b[i], d[i]);
	cout << b;
	return 0;
}
posted @ 2024-03-10 18:39  Vitamin_B  阅读(12)  评论(0)    收藏  举报  来源