63分求助

P1241 括号序列

迈吉扣 @ 2018-07-30 10:25:04

include<bits/stdc++.h>

using namespace std; char s[110]; int a[110]={0}; void luogu(int n)//看是否可以配对,不可以就标记为0 { for(int i=n;i>=0;i--) { if((s[i]==s[n]-1||s[i]==s[n]-2)&&a[i]!=1&&a[n]!=1) { a[i]=1;a[n]=1; break; } } } void openjudge(int n)//输出 { if(s[n]=='(') cout<<"()"; if(s[n]==')') cout<<"()"; if(s[n]=='[') cout<<"[]"; if(s[n]==']') cout<<"[]"; } int main() { cin>>s; int l=strlen(s); for(int i=0;i<l;i++) { if(s[i]==')'||s[i]==']')//开始配对 luogu(i); } for(int i=0;i<l;i++) { if(a[i]!=0) cout<<s[i];//说明配对成功,输出 else openjudge(i);//调用函数 } }


by 迈吉扣 @ 2018-07-30 10:25:29

啊呀


by 迈吉扣 @ 2018-07-30 10:25:42

#include<bits/stdc++.h>
using namespace std;
char s[110];
int a[110]={0};
void luogu(int n)//看是否可以配对,不可以就标记为0 
{
    for(int i=n;i>=0;i--)
    {
        if((s[i]==s[n]-1||s[i]==s[n]-2)&&a[i]!=1&&a[n]!=1)
        {
            a[i]=1;a[n]=1;
            break;
        }
    }
}
void openjudge(int n)//输出 
{
    if(s[n]=='(') cout<<"()";
    if(s[n]==')') cout<<"()";
    if(s[n]=='[') cout<<"[]";
    if(s[n]==']') cout<<"[]";
}
int main()
{
    cin>>s;
    int l=strlen(s);
    for(int i=0;i<l;i++)
    {
        if(s[i]==')'||s[i]==']')//开始配对 
        luogu(i);
    }
    for(int i=0;i<l;i++)
    {
        if(a[i]!=0)
        cout<<s[i];//说明配对成功,输出 
        else
        openjudge(i);//调用函数 
    }
}

by 迈吉扣 @ 2018-07-30 10:26:21

忘记整理代码了


by 迈吉扣 @ 2018-08-01 08:26:32

\color{red}\colorbox{red}{对啊!} \color{orange}\colorbox{orange}{对啊!} \color{yellow}\colorbox{yellow}{对啊!} \color{green}\colorbox{green}{对啊!} \color{cyan}\colorbox{cyan}{对啊!} \color{blue}\colorbox{blue}{对啊!} \color{purple}\colorbox{purple}{对啊!} \color{gray}\colorbox{gray}{对啊!} \color{pink}\colorbox{pink}{对啊!} \color{black}\colorbox{black}{对啊!} \color{white}\colorbox{white}{对啊!} \color{brown}\colorbox{brown}{对啊!} \color{beige}\colorbox{beige}{对啊!} \color{palegoldenrod}\colorbox{palegoldenrod}{对啊!} \color{sienna}\colorbox{sienna}{对啊!} \color{tan}\colorbox{tan}{对啊!} \color{teal}\colorbox{teal}{对啊!} \color{wheat}\colorbox{wheat}{对啊!} \color{yellowgreen}\colorbox{yellowgreen}{对啊!} \color{gold}\colorbox{gold}{对啊!} \color{fuchsia}\colorbox{fuchsia}{对啊!} \color{sandybrown}\colorbox{sandybrown}{对啊!}

by 迈吉扣 @ 2018-08-01 08:26:37

\color{red}\colorbox{red}{对啊!} \color{orange}\colorbox{orange}{对啊!} \color{yellow}\colorbox{yellow}{对啊!} \color{green}\colorbox{green}{对啊!} \color{cyan}\colorbox{cyan}{对啊!} \color{blue}\colorbox{blue}{对啊!} \color{purple}\colorbox{purple}{对啊!} \color{gray}\colorbox{gray}{对啊!} \color{pink}\colorbox{pink}{对啊!} \color{black}\colorbox{black}{对啊!} \color{white}\colorbox{white}{对啊!} \color{brown}\colorbox{brown}{对啊!} \color{beige}\colorbox{beige}{对啊!} \color{palegoldenrod}\colorbox{palegoldenrod}{对啊!} \color{sienna}\colorbox{sienna}{对啊!} \color{tan}\colorbox{tan}{对啊!} \color{teal}\colorbox{teal}{对啊!} \color{wheat}\colorbox{wheat}{对啊!} \color{yellowgreen}\colorbox{yellowgreen}{对啊!} \color{gold}\colorbox{gold}{对啊!} \color{fuchsia}\colorbox{fuchsia}{对啊!} \color{sandybrown}\colorbox{sandybrown}{对啊!}

by 迈吉扣 @ 2018-08-01 08:26:44

\color{red}\colorbox{red}{对啊!} \color{orange}\colorbox{orange}{对啊!} \color{yellow}\colorbox{yellow}{对啊!} \color{green}\colorbox{green}{对啊!} \color{cyan}\colorbox{cyan}{对啊!} \color{blue}\colorbox{blue}{对啊!} \color{purple}\colorbox{purple}{对啊!} \color{gray}\colorbox{gray}{对啊!} \color{pink}\colorbox{pink}{对啊!} \color{black}\colorbox{black}{对啊!} \color{white}\colorbox{white}{对啊!} \color{brown}\colorbox{brown}{对啊!} \color{beige}\colorbox{beige}{对啊!} \color{palegoldenrod}\colorbox{palegoldenrod}{对啊!} \color{sienna}\colorbox{sienna}{对啊!} \color{tan}\colorbox{tan}{对啊!} \color{teal}\colorbox{teal}{对啊!} \color{wheat}\colorbox{wheat}{对啊!} \color{yellowgreen}\colorbox{yellowgreen}{对啊!} \color{gold}\colorbox{gold}{对啊!} \color{fuchsia}\colorbox{fuchsia}{对啊!} \color{sandybrown}\colorbox{sandybrown}{对啊!}

by Cheney @ 2019-08-15 16:34:03

本蒟蒻也63


by Diwanul @ 2019-08-15 22:41:05

@CHEN_RUI_PING 本来70的,改一改成了63……


by 尹昱钦 @ 2019-09-28 22:42:38

我也是63QAQ


|