求第一个点数据

P1944 最长括号匹配

附个代码qwq ```cpp #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; int n; int id[2000005],top; bool v[2000005],s[2000005]; char a[2000005]; int main(){ int i; char c; n=0; c=getchar(); while(c!='\n'){ a[++n]=c; c=getchar(); } n--; memset(v,0,sizeof(v)); top=0; for(i=1;i<=n;i++){ if(a[i]=='(')s[++top]=1,id[top]=i; else if(a[i]=='[')s[++top]=0,id[top]=i; else if(a[i]==')'){ if(top==0){ v[i]=0; continue; } if(s[top]==1)v[i]=v[id[top]]=1,top--; else top=0; } else{ if(top==0){ v[i]=0; continue; } if(s[top]==1)top=0; else v[i]=v[id[top]]=1,top--; } } int cnt=0,ans=0,p; for(i=1;i<=n;i++){ if(v[i]==1){ cnt++; if(ans<cnt){ ans=cnt; p=i; } } else cnt=0; } for(i=1;i<=ans;i++){ cout<<a[p-ans+i]; } return 0; } ```
by 易极feng @ 2018-09-05 19:04:39


已解决。 不过还是想问一个问题: 为什么把 ```cpp n=0 c=getchar(); while(c!='\n'){ a[++n]=c; c=getchar(); } ``` 改成 ```cpp scanf("%s",a); n=strlen(a); ``` 就没问题了? P.S.与编址起点无关。 回复请@,多谢!
by 易极feng @ 2018-09-05 19:13:49


@[易极feng](/space/show?uid=6973) '\n'是windows换行符,在不同评测环境下不同的啊……
by x义x @ 2018-09-05 19:21:06


其他点似乎都没有问题而且我以前一直这么写啊 @[x義x](/space/show?uid=58567)
by 易极feng @ 2018-09-05 19:26:28


@[易极feng](/space/show?uid=6973) 额……貌似问题不在这里 我也很迷啊……有可能是毒瘤数据?
by x义x @ 2018-09-05 19:28:21


@[x義x](/space/show?uid=58567) 用上面的方式惊奇地发现n为真实n+1 而那n+1位是个诡异的字符qwq
by 易极feng @ 2018-09-05 19:32:18


|