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

    输出;

    捕获

  • 相关阅读:
    myssl.com SSL 检测
    tp中model加载机制
    号码归属地
    七牛云刷新缓存
    盒子模型
    eclipse中将项目发布到tomcat的root目录
    php二维数组搜索
    linux 编译 'aclocal-1.14' is missing on your system
    windows安装 centos
    svn ignore 的用法
  • 原文地址:https://www.cnblogs.com/sanghai/p/2768965.html
Copyright © 2011-2022 走看看