这道题是寻找当前字符串的的子集,并且和当前比较的变换最小,也就是说未必是字典序最小,但是和当前的字典序应该是相差最小
#include <iostream> #include <string> #include <algorithm> using namespace std ; int main() { int t ; cin >> t; while(t--) { string s ; cin >> s ; if (next_permutation(s.begin(),s.end()) == false) cout << "no answer" << endl ; else cout << s << endl ; } return 0 ; }
此外 这里用到了next_permutation函数 详细用法 以后再谈。