| ||||||||||
| 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 | |||||||||
为什么会说wrong answer?? 麻烦高手来帮忙看一下。#include <iostream>
#include <fstream>
using namespace std;
char equation[1000];
void handle(char *s){
int slen=strlen(s);
int fx=0,count=0;//fx=x的系数,count=值的大小
int lr=1; //左边还是右边的等式。
int pn=1; //当前是正还是负
char a[100];//保存临时的数值
int aj=0;int i=0;
while(s[i]!='\0'){
if(s[i]=='='){
a[aj]='\0';
int p=lr*pn*atoi(a);
count+=p;
lr=-1;
pn=1;
aj=0;
/* cout<<fx<<" "<<count<<endl;
return;*/
}else if(s[i]=='-'){
a[aj]='\0';
int p=lr*pn*atoi(a);
count+=p;
pn=-1;
aj=0;
}else if(s[i]=='+'){
a[aj]='\0';
int p=lr*pn*atoi(a);
count+=p;
pn=1;
aj=0;
}else if(s[i]=='x'){
a[aj]='\0';
int p=lr*pn*atoi(a);
fx+=p;
aj=0;
}else{
if(s[i]>='0'&&s[i]<='9'){
a[aj++]=s[i];
}
}
i++;
if(s[i]=='\0'&&s[i-1]!='x'){
a[aj]='\0';
int p=lr*pn*atoi(a);
count+=p;
}
}
if(count==0&&fx==0){
cout<<"IDENTITY"<<endl;
}else if(count!=0&&fx==0){
cout<<"IMPOSSIBLE"<<endl;
}else{
int result=0;
float n=(float)(-1*count)/fx;
if(n>=0)result=(int)n;
else result=(int)n-1;
cout<<result<<endl;
}
}
void main(){
int testcase;
cin>>testcase;
for(int i=0;i<testcase;i++){
cin>>equation;
handle(equation);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator