站外题求助(玄关)

题目总版

https://www.luogu.com.cn/problem/CF915C
by yrx0115 @ 2024-04-27 14:13:33


``` #include <bits/stdc++.h> #define ls (r<<1) #define rs (r<<1|1) #define debug(a) cout << #a << " " << a << endl using namespace std; typedef long long ll; const ll maxn = 1e4+10; const ll mod = 1000000007; const double pi = acos(-1.0); const double eps = 1e-8; bool cmp( char p, char q ) { return p > q; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); string s1, s2; while( cin >> s1 >> s2 ) { ll len1 = s1.length(), len2 = s2.length(); sort(s1.begin(),s1.end()); if( len1 < len2 ) { reverse(s1.begin(),s1.end()); cout << s1 << endl; continue; } for( ll i = 0; i < len1; i ++ ) { for( ll j = len1-1; j > i; j -- ) { string t = s1; swap(s1[i],s1[j]); sort(s1.begin()+i+1,s1.end()); if( s1 > s2 ) { s1 = t; } else { break; } } //debug(s1); } cout << s1 << endl; } return 0; } ```
by EARS_TURE @ 2024-04-27 14:16:28


emmm....可以用char存数,然后找最大的一位,如果超过就用第二大
by yinzifan @ 2024-04-27 14:18:20


@[EARS_TURE](/user/1080324) 谢谢(已关)
by YSchencheche @ 2024-04-27 14:41:22


@[YSchencheche](/user/988515) 不谢awa
by EARS_TURE @ 2024-04-27 15:45:32


|