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 |
贴上代码~0MS#include <iostream> #include <string> using namespace std; int Sequence[50]; int PSequence[20]; int WSequence[20]; int index; int Wi; int main() { int caseNumber, pLen, d, sum; cin >> caseNumber; while (caseNumber-- > 0) { cin >> pLen; for (int i = 0; i < pLen; ++i) { cin >> PSequence[i]; } //-1:( 1:) index = 0; Wi = 0; for (int i = 0; i < PSequence[0]; ++i) { Sequence[index++] = -1; } Sequence[index++] = 1;//第一个右括号 for (int i = 1; i < pLen; ++i) { d = PSequence[i] - PSequence[i-1]; for (int j = 0; j < d; ++j) { Sequence[index++] = -1; } Sequence[index++] = 1; } for (int i = 0; i < index; ++i) { if(Sequence[i] == 1) { sum = 0; for (int k = i; k >= 0; k--) { sum += Sequence[k]; if(sum == 0) { WSequence[Wi++] = ((i-k)+1)/2; break; } } } } for (int i = 0; i < Wi; ++i) { cout<<WSequence[i]<<" "; } cout<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator