class Solution {
public:
string customSortString(string order, string s) {
vector<int> freq(26);
string ans;
for(auto ch : s) ++freq[ch-'a'];//freq[ch-'a']++;
for(auto ch : order)
{
if(freq[ch-'a']>0)//如果order里面的字符在s中存在
{
ans += string(freq[ch-'a'], ch);
freq[ch-'a'] = 0;
}
}
for(int i=0; i<26; i++)
{
if(freq[i]>0) ans += string(freq[i], i + 'a');
}
return ans;
}
};