e313. APCS 最少相異字母

宣告一個 Priority Queue 存儲"相異字元數"跟"字串" (記得 cmp 要用 greater)
然後遍歷每個字串並且用一個陣列記錄字元是否出現過 如果未曾出現過就+1 並把該字元設為已出現
最後再把資料丟進 PQ 所有字串都遍歷完後輸出 PQ 的頭就好啦~

code:

#include <bits/stdc++.h>
#define Youtong ios::sync_with_stdio(0); cin.tie(0)
#define pii pair<int, string> 
using namespace std;

priority_queue<pii, vector<pii>, greater<pii>> pq;
bool mp[27];

int main(){
    Youtong;
    int n;
    string s;
    cin >> n;
    for (int i = 0; i < n; i++){
        memset(mp, 0, sizeof(mp));
        cin >> s;
        int count = 0;
        for (auto c: s){
            if (!mp[c-'A']){
                mp[c-'A'] = 1;
                count++;
            }
        }

        pq.push({count, s});
    }

    cout << pq.top().second << '\n';
}