题意:直接模拟

注意,w[i]不能是0

 

#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>


namespace cc
{
    using std::cout;
    using std::endl;
    using std::cin;
    using std::map;
    using std::vector;
    using std::string;
    using std::sort;


    constexpr int N = 200;


    void solve()
    {
        string str;
        while (getline(cin, str))
        {
            int n = 0;
            int val = 0;
            int w[N];
            memset(w,0,sizeof(w));
            for (int i = 0;i < str.length();i++)
            {
                if (str[i] >= 'a'&& str[i] <= 'z')
                {
                    //add
                    val = val * 32 + (str[i] - 'a' + 1);
                }
                else if(val!=0)
                {
                    //blank
                    w[n++] = val;
                    val = 0;
                }
            }
            if (val != 0)
            w[n++] = val;
            //sort
            sort(w, w + n);
            int c = w[0];
            int ok = true;
            while (ok)
            {
                ok = false;

                for (int i = 0;i < n - 1;i++)
                {
                    for (int j = i + 1;j < n;j++)
                    {
                        if (c / w[i] % n == c / w[j] % n)
                        {
                            c = std::min((c / w[i] + 1)*w[i], (c / w[j] + 1)*w[j]);
                            ok = true;
                        }
                    }
                }
            }
            cout << str << endl;
            cout << c << endl<<endl;
        }
    }

};


int main()
{

#ifndef ONLINE_JUDGE
    freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
    cc::solve();

    return 0;
}