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 |
怎么会有错??帮帮忙!!!//2295 use two data one for const the other for coefficients #include<iostream.h> #include<stdio.h> #include<stdlib.h> main(){ int i=0,k=1,w=1,b=0,c=0,j=0,t; double n; char a[10],s[300]; scanf("%d",&t); getchar(); for(;t>0;t--){ gets(s); while(s[j++]!='\0'){ if(s[j-1]=='='){ a[i]='\0'; b+=w*k*atoi(a); i=0;w=-1; j++; if(s[j-1]=='+')k=1; else if(s[j-1]=='-')k=-1; else {a[i]=s[j-1];i++;} continue; } if(s[j-1]=='-'){ a[i]='\0'; b+=w*k*atoi(a); k=-1;i=0; continue; } else if(s[j-1]=='+'){ a[i]='\0'; b+=w*k*atoi(a); k=1;i=0; continue; } else{ if(s[j-1]=='x'){ a[i]='\0'; c+=(-w*k*atoi(a)); j++; if(s[j-1]=='-')k=-1; if(s[j-1]=='+')k=1; if(s[j-1]=='=')w=-1; if(s[j-1]=='\0')break; i=0;continue; } } if(s[j-1]-'0'>-1&&s[j-1]-'0'<10){ a[i]=s[j-1]; i++; } } if(s[j-1]!='x'&&s[j-2]!='x')b+=w*k*atoi(a); if(b==0&&c==0) cout<<"IDENTITY"<<endl; else if(b!=0&&c==0) cout<<"IMPOSSIBLE"<<endl; else{ n=b/c; if(n<0) w=(int)n-1; else w=(int)n; cout<<n<<endl; }i=0;k=1;w=1;b=0;c=0;j=0; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator