小白学编程


私信TA

用户名:dotcpp0666798

访问量:207

签 名:

等  级
排  名 15162
经  验 828
参赛次数 1
文章发表 2
年  龄 0
在职情况 学生
学  校 河北师范大学汇华学院
专  业

  自我简介:

解题思路:map存储字符,循环遍历

注意事项: 记得getchar()清空缓冲区

参考代码:

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace  std;
int N,M;
string S;
char ch;
map<char ,int> mp;

signed main(){
//    IOS;
    cin>>N>>M>>S;getchar();
    for(int i=0;i<M;++i){
        cin>>ch;
        mp[ch]++;
    }
    auto it=mp.begin();
    for(char i : S){
        while(it != mp.end() && i > it->first){
            cout<<string(it->second,it->first);
            it++;
        }
        cout<<i;
    }
    while (it != mp.end()){
        cout<<string(it->second,it->first);
        it++;
    }
    return  0;
}


 

0.0分

2 人评分

  评论区

  • «
  • »