如何解决这个问题?

问题描述

  1. 验证外星词典

在外星语言中,令人惊讶的是他们也使用英文小写 字母,但顺序可能不同。字母顺序 是一些小写字母的排列。

给定一个用外星语言写的单词序列,以及顺序 字母表中,当且仅当给定的单词已排序时返回 true 用这种外来语言按字典顺序排列。

代码

class Solution
{
public:
    static vector<pair<char,int>> dict;

public:
    static bool compare(string tst1,string tst2)
    {
        if (tst1 == tst2)
        {
            return true;
        }
        int l1 = tst1.size();
        int l2 = tst2.size();
        int n = min(l1,l2);
        int flag = 0;
        for (int i = 0; i < n; i++)
        {
            if (tst1[i] == tst2[i])
                continue;
            if (tst1[i] != tst2[i])
            {
                flag = 1;
                int a = 0,b = 0;
                for (int j = 0; j < 26; j++)
                {
                    if (tst1[i] == dict[j].first)
                        a = dict[j].second;
                    if (tst2[i] == dict[j].first)
                        b = dict[j].second;
                    if (a != 0 && b != 0)
                        break;
                }
                if (a > b)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }
        if (flag == 0)
        {
            return true;
        }
        return true;
    }

public:
    bool isAlienSorted(vector<string> &words,string order)
    {
        int n = words.size();
        vector<string> comp;
        for (int i = 0; i < n; i++)
        {
            comp.push_back(words[i]);
        }
        for (int i = 0; i < 26; i++)
        {
            dict.push_back(make_pair(order[i],i + 1));
        }
        sort(words.begin(),words.end(),compare);
        int flag = 1;
        for (int i = 0; i < n; i++)
        {
            if (words[i] != comp[i])
            {
                flag = 0;
                break;
            }
        }
        if (flag)
            return true;
        else
            return false;
    }
};

错误->

ld.lld: error: undefined symbol: Solution::dict
>>> referenced by prog_joined.cpp
>>>               /tmp/prog_joined-0fc27f.o:(Solution::isAlienSorted(std::vector<std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::__cxx11::basic_string<char,std::allocator<char> > > >&,std::__cxx11::basic_string<char,std::allocator<char> >))
>>> referenced by prog_joined.cpp
>>>               /tmp/prog_joined-0fc27f.o:(Solution::compare(std::__cxx11::basic_string<char,std::allocator<char> >))
>>> referenced 1 more times
clang-11: error: linker command Failed with exit code 1 (use -v to see invocation)

为什么我会收到这个错误?我无法理解。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)