关注
#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%通过
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
03-03 14:54
河南大学 Java 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# AI面会问哪些问题? #
13197次浏览 271人参与
# 你做过最难的笔试是哪家公司 #
16076次浏览 109人参与
# 米连集团26产品管培生项目 #
11828次浏览 276人参与
# 你的实习产出是真实的还是包装的? #
13941次浏览 209人参与
# 找AI工作可以去哪些公司? #
3614次浏览 81人参与
# 春招至今,你的战绩如何? #
43589次浏览 382人参与
# 开放七大实习专项,百度暑期实习值得冲吗 #
8516次浏览 115人参与
# 从事AI岗需要掌握哪些技术栈? #
3798次浏览 110人参与
# 机械/制造每日一题 #
91898次浏览 1491人参与
# 阿里笔试 #
167620次浏览 1204人参与
# 春招你拿到offer了吗 #
822226次浏览 9946人参与
# 应届生进小公司有什么影响吗 #
132635次浏览 1188人参与
# 长得好看会提高面试通过率吗? #
17852次浏览 190人参与
# 学历对求职的影响 #
656000次浏览 4201人参与
# 应届生第一份工作最好去大厂吗? #
143238次浏览 1214人参与
# 沪漂/北漂你觉得哪个更苦? #
6777次浏览 119人参与
# 一张图晒出你司的标语 #
2318次浏览 35人参与
# HR最不可信的一句话是__ #
3814次浏览 75人参与
# AI时代,哪个岗位还有“活路” #
7572次浏览 206人参与
# 职场新人体验 #
180290次浏览 1215人参与
# 工作丧失热情的瞬间 #
374844次浏览 2574人参与
# 什么专业适合考公 #
58456次浏览 303人参与
查看9道真题和解析