原题题目
代码实现(首刷部分看解部分自解)
class Solution {
public:string longestDiverseString(int a, int b, int c) {
string ret;vector<pair<int,char>> v{
{
a,'a'},{
b,'b'},{
c,'c'}};int sum = a+b+c;while(1){
sort(v.begin(),v.end(),greater<pair<int,char>>());auto& pairmax = *v.begin();auto& pairsecond = *(v.begin()+1);if(!pairmax.first) break;int temp = min(pairmax.first,2);ret += pairmax.second;if(temp == 2) ret += pairmax.second;int count = 0;if(!(sum-pairmax.first)) break;if(pairmax.first > (sum-pairmax.first)*2) count = 1;else count = 2;ret += pairsecond.second;count = min(pairsecond.first,count);if(count == 2) ret += pairsecond.second;pairmax.first -= temp;pairsecond.first -= count;sum -= (temp+count);}return ret;}
};