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 |
谁能给我点测试数据啊。总是WA啊。。。#include<iostream> #include<string> using namespace std; string str; bool panB(int beg,int end, bool *a) { if(beg==0)return 1; int i; for(i=beg-1;i>=0;--i)if(str[i]!=' ')break; if(i<0)return 1; if(str[i] == '('|| str[i]== '+' ) return 1; if(str[i] == '/')return 0; if(a[0]||a[1])return 0; else return 1; } bool panE(int beg,int end,bool *a) { if(end==str.size()-1)return 1; int i; for(i=end+1;i<str.size();++i)if(str[i]!=' ')break; if(i>=str.size())return 1; if(str[i]=='+'||str[i]=='-')return 1; if(a[0]||a[1])return 0; else return 1; } int main(int argc, char* argv[]) { int n, i, j, flag1, flag2; cin>>n; while(n--) { cin>>str; int count = 0; for(i=0;i<str.size();++i) { bool fhao[2] = {0}; if(str[i]=='(') { flag1 = i; count ++; for(j=i+1;j<str.size();++j) { if(str[j]=='(') count++; if(str[j]==')') { count --; if(!count) { flag2 = j; break; } } if(count==1) { if(str[j]=='+') fhao[0] = 1; if(str[j]=='-') fhao[1] = 1; } } } else continue; if(panB(flag1,flag2,fhao) && panE(flag1,flag2,fhao)) { str[flag1] = ' '; str[flag2] = ' '; } } for(i=0;i<str.size();++i) { if(str[i]==' ')continue; cout<<str[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