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 |
奇怪,老是wrong answer??自己测试好像没发现什么错误啊 测试数据中是不是有什么容易忽略的东东? #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int n,x,y,result; int num=0; char ch,ch2,flag; char finish=0; string str; cin>>n; while(n-->0){ x=0,y=0; result=0; flag=1; finish=0; cin>>str; istringstream cins(str); while(!finish&&cins.get(ch)){ switch(ch){ case 'x':// read x if(flag) x++; else x--; break; case '+':// read '+' cins.get(ch); if(ch=='x'){ if(flag) x++; else x--; break; } cins.putback(ch); if(isdigit(ch)){ cins>>num; cins.get(ch2); if(ch2!='x'){ cins.putback(ch2); if(flag) y+=num; else y-=num; } else{ if(flag) x+=num; else x-=num; } break; } else{ x=0; finish=1; continue; } case '-'://read '-' cins.get(ch); if(ch=='x'){ if(flag) x--; else x++; break; } cins.putback(ch); if(isdigit(ch)){ cins>>num; cins.get(ch2); if(ch2!='x'){ cins.putback(ch2); if(flag) y-=num; else y+=num; } else{ if(flag) x-=num; else x+=num; } break; } else{ x=0; finish=1; continue; } case '=':// read '=' flag=0; break; case '0':case '1':case '2':case '3':case '4':case '5': case '6':case '7':case '8':case '9': cins.putback(ch); cins>>num; cins.get(ch2); if(ch2!='x'){ cins.putback(ch2); if(flag) y+=num; else y-=num; } else{ if(flag) x+=num; else x-=num; } break; default: x=0; finish=1; } } if(!x){ cout<<"IDENTITY"<<endl; continue; } result=0-y/x; cout<<result<<endl; } return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator