Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
91664 sh25_shenpy 扩号匹配问题 C++ 解答错误 0 MS 248 KB 1159 2026-06-14 14:20:56

Tests(0/1):


#include <iostream> #include <string> #include <stack> using namespace std; int main() { string str; // 持续读取每行输入,处理多组数据 while (getline(cin, str)) { int n = str.size(); string flag(n, ' '); // 标记串,初始全空格 stack<int> st; for (int i = 0; i < n; ++i) { if (str[i] == '(') { st.push(i); // 左括号下标入栈 } else if (str[i] == ')') { if (!st.empty()) { st.pop(); // 成功匹配,出栈 } else { flag[i] = '?'; // 无匹配的右括号 } } // 字母不作处理,保持空格 } // 处理剩余未匹配的左括号 while (!st.empty()) { int pos = st.top(); st.pop(); flag[pos] = '$'; } // 输出结果 cout << str << endl; cout << flag << endl; } return 0; }


测评信息: