给你一个字符串 text,你需要使用 text 中的字母来拼凑尽可能多的单词 “balloon”(气球)。
字符串 text 中的每个字母最多只能被使用一次。请你返回最多可以拼凑出多少个单词 “balloon”。
示例 1:
输入:text = “nlaebolko”
输出:1
示例 2:
输入:text = “loonbalxballpoon”
输出:2
示例 3:
输入:text = “leetcode”
输出:0
提示:
1 <= text.length <= 10^4
text 全部由小写英文字母组成
代码:
#include <iostream>
using namespace std;
class Solution {
public:
int isPalindrome(string x) {
char a[5]={'a','b','l','o','n'};
int b[5]={0};
for(int i=0;i<x.length();i++)
for(int j=0;j<5;j++)
{ if(x[i]==a[j])
b[j]++;}
b[2]=b[2]/2;
b[3]=b[3]/2;
for(int i=1;i<5;i++)
if(b[i]<b[0])
b[0]=b[i];
return (b[0]);
}
};
int main()
{
Solution z;
string x;
cin>>x;
cout<<z.isPalindrome(x)<<endl;
return 0;
}