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

x+x+x=9+x 你会报错,你没有考虑多个x的问题。

Posted by zhb_msqx at 2007-08-14 21:39:28 on Problem 2295
In Reply To:怎么会有错??帮帮忙!!! Posted by:13 at 2007-04-14 20:49:33
> //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:
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