关注
#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%通过
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
- 1... AI Agent 面试 Top50 必刷题1.7W
- 2... 看不懂组内文档,实习怎么偷产出?8308
- 3... 五月了,感觉实习很难找了6029
- 4... 解决了xd们,发了个dy曝光视频,十几万播放,直接让他火速联系我,赔我路费了,兄弟们碰到不公平的违法行为,一定要积极捍卫自己权益5730
- 5... 妈妈只想要你快乐3980
- 6... 要对实习同事表白吗?3734
- 7... 26届双非本求职总结3598
- 8... 三段大厂,说下我见过的最低学历3098
- 9... 实习一个星期,我因为只加了20分钟班被开除了3035
- 10... 理性讨论,卷实习算不算工贼行为?3035
正在热议
更多
# 26届春招投递记录 #
36716次浏览 311人参与
# 你今年的平均薪资是多少? #
230258次浏览 1069人参与
# 如何成为1个AI工程师? #
5847次浏览 285人参与
# 携程笔试 #
180096次浏览 928人参与
# 27届实习投递记录 #
122205次浏览 1386人参与
# 我想象的实习vs现实的实习 #
340837次浏览 2316人参与
# 求职你最看重什么? #
170423次浏览 915人参与
# 秋招提前批,你开始投了吗 #
766652次浏览 8495人参与
# 工作丧失热情的瞬间 #
401295次浏览 2589人参与
# 要毕业了,再不说就来不及了 #
9423次浏览 154人参与
# 哪些公司校招卡第一学历 #
262498次浏览 879人参与
# 硬件人的简历怎么写 #
349642次浏览 3141人参与
# 国庆假期,给大脑放个假 #
26942次浏览 121人参与
# 你在职场上见过哪些“水货”同事 #
42006次浏览 179人参与
# 机械人的秋招小目标 #
32959次浏览 251人参与
# 面试被问第一学历差时该怎么回答 #
297241次浏览 2306人参与
# 你觉得机械有必要实习吗 #
89123次浏览 537人参与
# AI面会问哪些问题? #
136953次浏览 3696人参与
# 提名点击就挂的公司 #
146714次浏览 494人参与
# 听到哪句话就代表面试稳了or挂了? #
271383次浏览 1733人参与
查看29道真题和解析
