Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么这样也会错的??? QQ:247415211 大家讨论啊#include <iostream> #include <fstream> using namespace std; int main() {// fstream inFile("1.txt"); int t,n,p[21]; char parentheses[41]; int pair[21]; int i,j,cp,k; p[0]=0; inFile>>t; // cin>>t; while(t--) { inFile>>n; // cin>>n; i=1; while(i<=n) inFile>>p[i++]; // cin>>p[i++]; j=1; for(i=0;i<n-1;i++) { cp=p[i+1]-p[i]; for(k=1;k<=cp;k++) parentheses[j++]='('; parentheses[j]=')'; j++; } parentheses[j]=')'; parentheses[j+1]='\0';//将字符串形成 for(j=i=1;i<=2*n;i++) { if(parentheses[i] == '(')//用PRIA数组记录'('的下标 pair[j++]=i; else //遇到配对的,与前面的的下标相减就是2个配对括号之间的左右括号总数 { cout<<(i-pair[j-1]+1)/2<<" "; j--;//删除已经配过对的'(' } } cout<<endl; } return 7; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator