• 单词接龙~~


    #include
    #include
    #include
    using namespace std;

    vector word_list;

    void sort_word_list(string end_alpha) 
    {
        for (int i = 0; i < word_list.size() - 1; i++) 
        {
            for (int j = i + 1; j < word_list.size(); j++) 
            {
                if (word_list[i].find(end_alpha) == 0) 
                {
                    if (word_list[j].find(end_alpha) == 0) 
                    {
                        if (word_list[i].length() == word_list[j].length()) 
                        {
                            if (word_list[i] > word_list[j]) 
                            {
                                swap(word_list[i], word_list[j]);
                            }
                        } 
                        else if (word_list[i].length() < word_list[j].length()) 
                        {
                            swap(word_list[i], word_list[j]);
                        }
                    } 
                } 
                else 
                {
                    if (word_list[j].find(end_alpha) == 0) 
                    {
                        swap(word_list[i], word_list[j]);
                    }
                }
            }
        }
    }

    int main() 
    {
        int index, num;
        cin >> index >> num;
        cin.ignore();
        for (int i = 0; i < num; i++) 
        {
            string word;
            getline(cin, word);
            word_list.push_back(word);
        }
        string ans = word_list[index];
        string end_alpha = ans.substr(ans.length() - 1, 1);
        word_list.erase(word_list.begin() + index);

        sort_word_list(end_alpha);

        while (true) 
        {
            if (word_list.size() == 0) 
            {
                break;
            }
            if (word_list[0].find(end_alpha) != 0) 
            {
                break;
            }

            ans += word_list[0];
            word_list.erase(word_list.begin());
            end_alpha = ans.substr(ans.length() - 1, 1);
            sort_word_list(end_alpha);
        }

        cout << ans << endl;

        return 0;
    }
     

  • 相关阅读:
    360T7路由器进行WiFi无线中继教程
    【2024秋招】2023-9-14 最右后端开发线下一面
    Git基础使用
    25分钟了解命令执行漏洞【例题+详细讲解】(一)
    python——numpy库函数详解
    BNU002期-学术沙龙-写好综述
    P1182 数列分段 Section II——二分答案
    Qt实现2D绘图
    深度学习【使用seq2seq实现聊天机器人】
    哈希表的概念
  • 原文地址:https://blog.csdn.net/xlfdlbx/article/details/136787500