关注
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
#include <set>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <unordered_map>
#include <deque>
#include <sstream>
using namespace std;
void replace(string str, const string &bitset, unordered_map<int, int> &record, char nc){
bool flag = false;
int idx = 1;
int i = bitset.size() - 1;
while(i >= 0) {
if(bitset[i] == '1') {
int strIdx = record[idx];
str[strIdx] = nc;
flag = true;
}
--i;
++idx;
}
if(flag) {
cout << ',' << str;
}
}
bool nextBitSet(string &bitset) {
const int len = bitset.size();
if(bitset[len-1] == '0') {
bitset[len-1] = '1';
return true;
}
int curIdx = len-1;
while(curIdx >= 0) {
if(bitset[curIdx] == '0') {
bitset[curIdx] = '1';
break;
}
bitset[curIdx--] = '0';
}
if(curIdx < 0) return false;
return true;
}
int main()
{
string str;
char oc, nc;
cin >> str >> oc >> nc;
oc = tolower(oc);
unordered_map<int, int> record;
const int len = str.size();
int idx = 1;
int maxIdx = -1;
bool found = false;
for(int i = len-1; i >= 0; --i) {
char ch = tolower(str[i]);
if(ch == oc) {
found = true;
record[idx++] = i;
maxIdx = (idx > maxIdx? idx : maxIdx);
}
}
if(found) {
string bitset(maxIdx-1, '0');
cout << str;
while(nextBitSet(bitset)) {
replace(str, bitset, record, nc);
}
cout << endl;
}else{
cout << str << endl;
}
return 0;
}
100%通过
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 你现在会用到哪些AI技能? #
9414次浏览 95人参与
# 腾讯工作体验 #
514900次浏览 3551人参与
# 平安产险科技校招 #
1126次浏览 0人参与
# 大厂VS公务员你怎么选 #
33776次浏览 449人参与
# 我的求职进度条 #
102286次浏览 1298人参与
# 发面经攒人品 #
2620382次浏览 35804人参与
# 未岚大陆求职进展汇总 #
8961次浏览 88人参与
# 我对___祛魅了 #
132970次浏览 738人参与
# 来聊聊机械薪资天花板是哪家 #
145247次浏览 801人参与
# 你还有多少年退休? #
27261次浏览 192人参与
# 多益网络工作体验 #
55391次浏览 292人参与
# 小马智行求职进展汇总 #
14030次浏览 50人参与
# 实习在多还是在精 #
36911次浏览 259人参与
# 工作中的卑微时刻 #
25319次浏览 175人参与
# 机械人与华为的爱恨情仇 #
132850次浏览 1008人参与
# 顺丰求职进展汇总 #
63935次浏览 316人参与
# 秋招踩过的“雷”,希望你别再踩 #
88979次浏览 1110人参与
# 你的房租占工资的比例是多少? #
65669次浏览 802人参与
# 你觉得材料多少算高薪 #
26551次浏览 159人参与
# 实习下班不想学习,正常吗? #
22228次浏览 184人参与
# 反问环节如何提问 #
115978次浏览 2472人参与
# 如果不考虑收入,你最想做什么工作? #
33100次浏览 190人参与