现在的位置: 首页 > 综合 > 正文

HackerRank Bigger is Greater

2018年02月20日 ⁄ 综合 ⁄ 共 308字 ⁄ 字号 评论关闭

这道题是寻找当前字符串的的子集,并且和当前比较的变换最小,也就是说未必是字典序最小,但是和当前的字典序应该是相差最小

#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函数 详细用法 以后再谈。

抱歉!评论已关闭.