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

    输出;

    捕获

  • 相关阅读:
    Semaphore使用
    不可变对象
    Java锁--Lock实现原理(底层实现)
    Lambda Expressions and Functional Interfaces: Tips and Best Practices
    注解的作用
    linux命令大全
    linux &和&&,|和||
    SpringCloud 商品架构例子(一)
    springcloud starter(一)
    dubbo(一)
  • 原文地址:https://www.cnblogs.com/sanghai/p/2768965.html
Copyright © 2011-2022 走看看