CF-gym102700B

Baby name

#include<bits/stdc++.h>
using namespace std;
string a, b;

string solve(string x)
{
    int len = x.size();
    string t1, t2;
    // t1 += x[0];
    for (int i = 0; i < len; ++i) {
        // if (x[i] > t1[0]) {
        //     t1.clear();
        //     t1 += x[i];
        // }
        // else {
        //     if (x[i] < t1[0]) {
        //         t1 += x[i];
        //         t2 += x[i];
        //     }
        //     else {
        //         if(t2.empty()){
        //             t2+=x[i];
        //             t1+=x[i];
        //         }else{
                    
        //         }
        //     }
        // }
        // if(x[i]>t1[0]){
        //     t1.clear();
        //     t1+=x[i];
        // }else if(x[i]==t1[0]){
        //     t1+=x[i];
        //     t2+=x[i];
        // }else{
        //     if(t2.empty()){
        //         t1+=x[i];
        //     }else{
        //         t1+=x[i];
        //         t2+=x[i];
        //         if(t2[t2.length()-1]>t1[t2.length()-1]){
        //             t1=t2;
        //             t2.clear();
        //         }else{
        //             t2.clear();
        //         }
        //     }
        // }
        if(t1.empty() || x[i]>t1[0]){
            t1.clear();
            t2.clear();
            t1+=x[i];
        }else if(x[i]==t1[0]){
            t1+=x[i];
            if(t2.empty()){
                t2+=x[i];
            }else{
                t2+=x[i];
                if(t2[t2.length()-1]>t1[t2.length()-1]){
                    t1=t2;
                    t2=x[i];
                }else if(t2[t2.length()-1]<t1[t2.length()-1]){
                    t2=x[i];
                }
            }
            //t2+=x[i];
        }else{
            t1+=x[i];
            if(t2.length()){
                t2+=x[i];
                if(t2[t2.length()-1]>t1[t2.length()-1]){
                    t1=t2;
                    t2.clear();
                }else if(t2[t2.length()-1]<t1[t2.length()-1]){
                    t2.clear();
                }
            }
        }
    }
    return max(t1, t2);
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> a >> b;
    //int lena=a.size(),lenb=b.size();
    string aCopy = solve(a);
    string bCopy = solve(b);
    //cout << aCopy << " " << bCopy << "\n";
    int lena = aCopy.size(), lenb = bCopy.size();
    int l1 = 1;
    for (;; l1++) {
        if (l1 > lena ) break;
        if (aCopy[l1] < bCopy[0]) break;
    }
    for (int i = 0; i < l1; ++i) cout << aCopy[i];
    cout << bCopy <<"\n";
    return 0;
}

/*
zbazbazy
xabxbaxy
*/

/*
zbazyzba
xabxbaxy
*/
posted @ 2020-10-05 21:12  0xDkXy_DWM  阅读(162)  评论(0编辑  收藏  举报