字符覆盖
题目:输入两个字符串,结果使用字典序排列;
输入:fedcba
ee
输出:feeeba
实现:
1.字典序:{'b'>'a'}
2.对输入的原始字符串排序,然后针对每一个字符与现有的字符串比较,考虑是否替换;
#include<bits/stdc++.h>
using namespace std;
string s,t;
int cmp(int a,int b){
    return a>b;
}
int main(){
    cin>>s>>t;
    sort(t.begin(),t.end(),cmp);
    int pos = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] < t[pos]){
            s[i] = t[pos];
            pos++;
        }
    }
    cout<<s<<endl;
    return 0;
}

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号