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 n次了,还没找到错在哪?求高人指点#include<iostream> #include<string.h> using namespace std; char a[300]; void fun() { int i,len,num=0,z=0,temp=0,p=1,q=1,k; double d; len=strlen(a); if(a[0]=='x') z=1; for(i=0;i<len;++i) { if('0'<=a[i]&&a[i]<='9') { temp=temp*10+a[i]-'0'; if(i==len-1) { num+=temp*q*p; } continue; } if(a[i]=='x'&&i!=0) { if(temp==0) z+=1*p*q; else z+=temp*p*q; temp=0; p=1; continue; } if(a[i]=='+'&&a[i-1]!='x') { num+=temp*p*q; temp=0; p=1; continue; } if(a[i]=='-'&&a[i-1]!='x') { num+=temp*p*q; temp=0; p=-1; continue; } if(a[i]=='+'&&a[i-1]=='x') { z+=temp*p*q; temp=0; p=1; continue; } if(a[i]=='-'&&a[i-1]=='x') { z+=temp*p*q; temp=0; p=-1; continue; } if(a[i]=='=') { if(a[i-1]=='x') z+=temp*p*q; else num+=temp*p*q; q=-1; temp=0; continue; } } num=(-1)*num; if(z==0) { if(num==0) printf("IDENTITY\n"); else printf("IMPOSSIBLE\n"); } else { k=num/z; d=(double)num/(double)z; if(k>d) printf("%d\n",k-1); else printf("%d\n",k); } } int main() { //freopen("in.txt","r",stdin); int t; scanf("%d",&t); while(t--) { memset(a,'0',sizeof(char)); scanf("%s",a); fun(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator