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 |
为什么老是超时?可以请各位大虾帮忙看一下代码吗?#include<stdio.h> int ceiling(float m){ if(m>=0||m-(int)m==0) return (int)m; else return (int)m-1; } int main(){ int flag,j,sign,d,i,num,n[3],m[3]; char c,equ[260]; freopen("test.txt","r",stdin); scanf("%d",&num); for(i=0;i<num;i++){ flag=sign=n[0]=m[0]=n[1]=m[1]=0; scanf("%s",equ); for(j=0;(c=equ[j])!='\0';j++){ if(c>='0'&&c<='9'){ d=c-'0'; for(c=equ[++j];c>='0'&&c<='9';c=equ[++j]) d=d*10+c-'0'; if(c=='x') n[flag]+=d; else { if(sign) m[flag]-=d; else m[flag]+=d; if(c=='=') flag=1; else if(c=='+') sign=0; else if(c=='-') sign=1; else if(c=='\0') break; } } else if(c=='x'){ if(sign) n[flag]-=1; else n[flag]+=1; } else if(c=='=') flag=1; else if(c=='+') sign=0; else if(c=='-') sign=1; } n[2]=n[0]-n[1]; m[2]=m[1]-m[0]; if(n[2]==0&&m[2]==0) printf("IDENTITY\n"); else if(n[2]==0&&m[2]!=0) printf("IMPOSSIBLE\n"); else printf("%d\n",ceiling((float)m[2]/n[2])); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator