文章
34
粉丝
109
获赞
7
访问
21.3k
#include <stdio.h>
#include <string.h>
int main()
{
char s[105];
while (scanf("%s", s) != EOF)
{ // 用栈存 没有匹配的左括号的坐标
int top = -1, i = 0, top2 = -1;
char stack[105];
int stack1[105] = {0};
char cnt[105] = {'!'};
while (s[i] != '\0')
{
while (s[i] == '(')
{
stack[++top] = s[i++];
stack1[++top2] = i - 1;
}
if (s[i] == ')' && top == -1)
{
cnt[i] = '?';
i++;
}
else if (s[i] == ')' && stack[top] == '(')
{
top--;
top2--;
i++;
}
else if (s[i] != '(' || s[i] != ')')
{
i++;
}
}
while (top != -1)
{
cnt[stack1[top2--]] = '$';
top--;
}
...
登录后发布评论
暂无评论,来抢沙发