Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么老是超时?可以请各位大虾帮忙看一下代码吗?

Posted by aime at 2006-08-07 21:02:57 on Problem 2295
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator