zoukankan      html  css  js  c++  java
  • 字母重排

    例子

    //---------------MY CODE-------------------------
    #include<iostream>
    #include<vector>
    #include<string>
    using namespace std;
    
    string get(string word)
    {
        for(int i = 1; i != word.size(); ++i)
        {
            char key = word[i];
            for(int j = i-1; j >= 0 && word[j] > key; --j)        //升序
                word[j+1] = word[j];
            word[j+1] = key;
        }
        return word;
    }
    void marry(const vector<string> &dictionary, const string &word)
    {
        vector<string>::size_type i = 0;
        bool flag = false;
        for(; i != dictionary.size(); ++i)
        {
            if(get(word) == get(dictionary[i]) && word != dictionary[i])
            {
                if(flag == true)
                    cout << " ";
                cout << dictionary[i];
                flag = true;
            }
        }
        if(flag == false)
            cout << ":(";
        cout << endl;
    }
    int main()
    {
        vector<string> dictionary;
        cout << "Fill in the dictinory:" << endl;
        string word;
        while(cin >> word && word != "******")
            dictionary.push_back(word);
        cout << "Enter some words(Ctr+Z to end):" << endl;
        while(cin >> word)
        {
            marry(dictionary, word);
        }
        return 0;
    }

    例子:

    tarp given score refund only trap work earn course pepper part
    ******
      
    resco nfudre aptr sett oresuc

    输出;

    捕获

  • 相关阅读:
    Visual Studio2019安装步骤
    写在第一页的话
    数状数组
    hdu 3501 数学题
    静态邻接表
    最长子序列
    hdu 1094 所想到的
    bellman_ford
    郁闷的一晚
    SPFA + 静态邻接表 模板
  • 原文地址:https://www.cnblogs.com/sanghai/p/2768965.html
Copyright © 2011-2022 走看看