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> #include<string.h> #include<math.h> void main(){ char a[200]; int n,i,j,k,lenth,mid,p1,q1,r1; double o,p,q,r,b[100]; b['m'-'A']=0.001;b['M'-'A']=1000000;b['k'-'A']=1000; b[0]=1;b['V'-'A']=1;b['W'-'A']=1; scanf("%d\n",&n); for(i=1;i<=n;i++){ printf("Problem #%d\n",i); gets(a); lenth=strlen(a); p1=0;q1=0;r1=0; for(j=0;j<lenth;j++){ if(a[j]=='P'||a[j]=='I'||a[j]=='U'){ k=j+2;o=0; for(;;k++) if(a[k]<'0'||a[k]>'9') break; mid=k;k=j+2; for(;(a[k]>='0'&&a[k]<='9')||a[k]=='.';k++){ if(k<mid) o+=(a[k]-'0')*pow(10,mid-k-1); if(k>mid) o+=(a[k]-'0')*pow(10,mid-k); } o*=b[a[k]-'A']; switch(a[j]){ case 'P':{ p=o;p1=1;break; } case 'I':{ q=o;q1=1;break; } case 'U':{ r=o;r1=1;break; } } for(;;k++) if(a[k]=='A'||a[k]=='V'||a[k]=='W') break; j=k+1; } } if(p1==0) printf("P=%.2lfW\n\n",q*r); if(q1==0) printf("I=%.2lfA\n\n",p/r); if(r1==0) printf("U=%.2lfV\n\n",p/q); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator