ETH官方钱包

前往
大廳
主題

C/C++紀錄二十八<大神寫的摩斯密碼轉換+比較> 2018/12/2

艾倫D索妮雅 | 2021-06-09 19:42:22 | 巴幣 0 | 人氣 409

class Solution
{
    public:
       int uniqueMorseRepresentations(vector<string>& words)
       {
            vector<string> morse={".-","-...","-.-.","-..",".",
         "..-.","--.","....","..",".---",
             "-.-",".-..","--","-.","---",
          ".--.","--.-",".-.","...","-",
             "..-","...-",".--","-..-","-.--",
         "--.."};
      unordered_map<string,int> trans;
            for(auto &str:words)//words中,每個str字串
            {
                string s;
                for(auto c:str)//str中每個c字元
                {
                    s.append(morse[c-'a']);//用ACSII跑morse並附加到字串s中
                }
                trans[move(s)]++;
            }
           return trans.size();
       }
};

創作回應

更多創作