首页 > 其他 > 详细

leetcode804

时间:2018-09-27 13:45:13      阅读:136      评论:0      收藏:0      [点我收藏+]
int uniqueMorseRepresentations(vector<string>& words) {
    map<char, string> st;
    st.insert(make_pair(a, ".-"));
    st.insert(make_pair(b, "-..."));
    st.insert(make_pair(c, "-.-."));
    st.insert(make_pair(d, "-.."));
    st.insert(make_pair(e, "."));
    st.insert(make_pair(f, "..-."));
    st.insert(make_pair(g, "--."));

    st.insert(make_pair(h, "...."));
    st.insert(make_pair(i, ".."));
    st.insert(make_pair(j, ".---"));
    st.insert(make_pair(k, "-.-"));
    st.insert(make_pair(l, ".-.."));
    st.insert(make_pair(m, "--"));
    st.insert(make_pair(n, "-."));

    st.insert(make_pair(o, "---"));
    st.insert(make_pair(p, ".--."));
    st.insert(make_pair(q, "--.-"));
    st.insert(make_pair(r, ".-."));
    st.insert(make_pair(s, "..."));
    st.insert(make_pair(t, "-"));

    st.insert(make_pair(u, "..-"));
    st.insert(make_pair(v, "...-"));
    st.insert(make_pair(w, ".--"));
    st.insert(make_pair(x, "-..-"));
    st.insert(make_pair(y, "-.--"));
    st.insert(make_pair(z, "--.."));

    map<string, int> stt;
    int count = 0;
    for (auto s : words)
    {
        string str = "";
        for (auto c : s)
        {
            str += st[c];
        }
        cout << str << endl;
        if (stt.find(str) != stt.end())//存在
        {
            
        }
        else
        {
            stt.insert(make_pair(str, 1));
            count++;
        }
    }
    return count;
}

 

leetcode804

原文:https://www.cnblogs.com/asenyang/p/9712512.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!