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 |
这就是没读题的下场,100%经典WA代码#include <iostream> using namespace std; int main(){ int i,a1,a2,a3,a4,len; //(1 )2 [3 ]4 string str; a1=0;a2=0;a3=0;a4=0; cin>>str; len=str.length(); for(i = 0 ;i < len; i++){ if(str[i] == '(' ){ if( a2 > 0 ) a2--; else a1++;} else if(str[i] == ')'){ if( a1 > 0 ) a1--; else a2++;} else if(str[i] == '['){ if( a4 > 0 ) a4--; else a3++;} else if(str[i] == ']'){ if( a3 > 0 ) a3--; else a4++;} } for(i = 0 ; i < a2;i++) cout<<"("; for(i = 0 ; i < a4;i++) cout<<"["; cout<<str; for(i = 0 ; i < a1;i++) cout<<")"; for(i = 0 ; i < a3;i++) cout<<"]"; cout<<endl; cout<<a1+a2+a3+a4<<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