Azamon Web Services CodeForces

编程入门 行业动态 更新时间:2024-10-25 05:26:44

Azamon <a href=https://www.elefans.com/category/jswz/34/1770958.html style=Web Services CodeForces"/>

Azamon Web Services CodeForces

一、内容

题意:问最多替换一对字符后是否能够严格小于另一个串(相等不算作严格小于)

二、思路

  • 当a作为c的前缀的时候,a比c小。
  • 我们只需要对a进行排序,然后找到与b(排序后的串)第一个不相等字符处,然后将a串这个位置换成b串的这个位置的字符。
  • 由于要变成最小的串,所以我们应该从a串的末尾进行查找,这样替换的串更小。

三、代码

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5005;
string a, b, c;
int t;
int main() {scanf("%d", &t);while (t--) {cin >> a >> c;b = a;sort(b.begin(), b.end());if (b >= c) printf("---\n");else {if (a == b || a < c) cout << a << endl;else {//替换第一个不相同的字符 替换的时候应该尽量选择后面的字符进行替换 for (int i = 0; i < a.size(); i++) {if (a[i] != b[i]) {for (int j = a.size() - 1; j >= 0; j--) {if (a[j] == b[i]) {swap(a[j], a[i]);break;}}break;} } if (a < c) cout << a << endl;else cout << "---" << endl;}} }return 0;
}

更多推荐

Azamon Web Services CodeForces

本文发布于:2024-02-13 22:25:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1760986.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Web   Azamon   CodeForces   Services

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!