提交时间:2026-04-04 20:55:30
运行 ID: 435330
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string p, c; cin >> p >> c; // 输入故障密码p和验证码c int len_p = p.size(); int len_c = c.size(); vector<string> candidates; // 存储所有合法候选密码 // 遍历所有可以放置c的起始位置 i for (int i = 0; i <= len_p - len_c; ++i) { string temp = p; // 复制原密码,用于生成候选 bool valid = true; // 检查当前位置是否能嵌入c(非?字符必须匹配) for (int j = 0; j < len_c; ++j) { if (temp[i + j] != '?' && temp[i + j] != c[j]) { valid = false; break; } } if (valid) { // 替换为c的字符 for (int j = 0; j < len_c; ++j) { temp[i + j] = c[j]; } // 剩余所有?替换为A(字典序最小) for (char& ch : temp) { if (ch == '?') ch = 'A'; } candidates.push_back(temp); } } // 找到字典序最小的候选密码 string ans = candidates[0]; for (string s : candidates) { if (s < ans) ans = s; } cout << ans << endl; return 0; }