括号匹配问题1153
2017-04-30 19:53
253 查看
#include "stdafx.h"
#include <stack>
#include <stdio.h>
#include<iostream>
using namespace std;
stack<int> s;
char str[100];
char ans[110];
int _tmain(int argc, _TCHAR* argv[])
{
while (cin >> str)
{
int i;
for (i = 0; str[i] != 0; i++){
if (str[i] == '('){
s.push(i);
ans[i] = ' ';
}
else if (str[i] == ')'){
if (s.empty() == false){
s.pop();
ans[i] = ' ';
}
else ans[i] = '?';
}
else ans[i] = ' ';
}
while (!s.empty()){
ans[s.top()] = '$';
s.pop();
}
ans[i] = 0;
puts(str);
puts(ans);
}
return 0;
}
#include <stack>
#include <stdio.h>
#include<iostream>
using namespace std;
stack<int> s;
char str[100];
char ans[110];
int _tmain(int argc, _TCHAR* argv[])
{
while (cin >> str)
{
int i;
for (i = 0; str[i] != 0; i++){
if (str[i] == '('){
s.push(i);
ans[i] = ' ';
}
else if (str[i] == ')'){
if (s.empty() == false){
s.pop();
ans[i] = ' ';
}
else ans[i] = '?';
}
else ans[i] = ' ';
}
while (!s.empty()){
ans[s.top()] = '$';
s.pop();
}
ans[i] = 0;
puts(str);
puts(ans);
}
return 0;
}
相关文章推荐
- 题目1153:括号匹配问题
- 九度题目1153:括号匹配问题
- 题目1153:括号匹配问题
- 栈的应用--九度1153.括号匹配问题
- 【学习笔记】〖九度OJ〗题目1153:括号匹配问题
- 九度OJ 题目1153:括号匹配问题
- 题目1153:括号匹配问题[栈]
- 题目1153:括号匹配问题(栈的应用)
- 九度OJ 1153 括号匹配问题
- 【学习笔记】〖九度OJ〗题目1153:括号匹配问题
- 题目1153:括号匹配问题
- 九度 OJ 题目1153:括号匹配问题
- 26-题目1153:括号匹配问题
- 九度OJ-1153-括号匹配问题
- 题目1153:括号匹配问题
- 题目1153:括号匹配问题 题目26
- 题目1153:括号匹配问题(2010年北京大学计算机研究生机试真题,堆栈的使用)
- 九度OJ-1153-括号匹配问题
- 【九度】题目1153:括号匹配问题
- 九度OJ 1153:括号匹配问题 (DP)