| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 91663 | sh25_shenpy | 扩号匹配问题 | C++ | 解答错误 | 0 MS | 252 KB | 1094 | 2026-06-14 14:19:56 |
#include <iostream> #include <string> #include <stack> using namespace std; int main() { string s; // 多组输入,逐行读取 while (getline(cin, s)) { int len = s.size(); string res(len, ' '); // 初始全为空格 stack<int> st; for (int i = 0; i < len; ++i) { if (s[i] == '(') { st.push(i); } else if (s[i] == ')') { if (!st.empty()) { st.pop(); // 匹配成功,不标记 } else { res[i] = '?'; // 右括号失配 } } // 字母直接忽略,保持空格 } // 处理剩余未匹配的左括号 while (!st.empty()) { int pos = st.top(); st.pop(); res[pos] = '$'; } // 输出结果 cout << s << endl; cout << res << endl; } return 0; }