解题思路: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 人评分