P10244 题解
贪心题。首先为了保证 的字典序小,当 时要交换, 时不交换。在 时,为了使 的字典序尽可能小,则当 时不交换,否则交换。
代码
# 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;
}

浙公网安备 33010602011771号