RT

#include "bits/stdc++.h"
using namespace std;

string s[1919], s1;

int hed[810];

int siz;

bool res(int x, int y) {
    for (int i = hed[x], j = hed[y]; i < s[x].size() && j < s[y].size(); ++j, ++i) {
        if (s[x][i] > s[y][j]) return true;
        else if (s[x][i] < s[y][j]) return false;
    }
    return false;
}

int main() {
    while (cin >> s1) {
        s[++siz] = s1;
    }
    s[0] = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    for (; ;) {
        bool flg = false;
        char c = 126;
        int w = 0;
        for (int i = 1; i <= siz; ++i) {
            if (hed[i] < s[i].size()) {
                flg = true;
                if (res(w, i)) {
                    c = s[i][hed[i]];
                    w = i;
                } 
            }
        }
        // cout<<c<<' '<<w<<endl;
        if (flg) {
            putchar(c);
            ++hed[w];
        } else break;
    }
}

2 条评论

  • @ 2023-1-19 12:46:55

    所以正解是啥?贪心?

    • @ 2023-1-18 15:32:52

      长短不同,怎么办? 比如 BA B 你会选第二个B,但实际选第一个更优

    • 1