zoukankan      html  css  js  c++  java
  • uva-188-枚举

    题意:直接模拟

    注意,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;
    }
  • 相关阅读:
    设计模式七大原则之单一职责原则
    机器学习入门与进阶
    Django之路
    Python编程之路
    Python练习1
    Docker入门与进阶
    运维相关
    Node.js(一)
    位运算
    双指针算法
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/9905266.html
Copyright © 2011-2022 走看看