#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair<int,int> pii;
//inline ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&(-x);return res;}
//inline void add(int x,int d){while(x<=n)c[x]+=d,x+=x&(-x);}
//int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b);}
const ll inf = 0x3f3f3f3f;
const int mx = 1e5+10;
char str[40],te[40];
double a,b,c;
double f(double x ){
// cout<<"x="<<x<<endl;
return a*x*x+b*x+c;
}
void calc(int pos){
// cout<<a<<" "<<b<<" "<<c<<endl;
printf("%06lf\n",f(-b/2/a));
// cout<<f(-b/2/a)<<endl;
return ;
}
int main(){
freopen("F:\\qq文件\\题目\\10\\problem2.in","r",stdin);
//int T=10; scanf("%d",&T);
while(scanf("%s",str) != EOF){
// a=b=c=0;
int len = strlen(str);
scanf("%s",str+len);
len =strlen(str);
// cout<<str<<endl;
int i;
a=b=c=0;
if(str[2] == 'x'){
a = 1;
i=5;
}
else{
int co=0;
for(i = 2; str[i] != '*'; i++){
te[co++] = str[i];
}
te[co++] = 0;
sscanf( te,"%lf", &a);
i+=4;
}
// cout<<"a="<<a<<endl;
if(str[i] == '('){
calc(i);
// return 0;
continue;
}
int flag=1;
if(str[i]=='-') flag=-1;
i++;
if(str[i] == 'x'){
b = 1*flag;
}
else{
int co=0;
for( ; str[i] != '*'&& str[i] != '('; i++){
te[co++] = str[i];
}
te[co++] = 0;
if(str[i] == '*'){
sscanf(te,"%lf", &b);
b*=flag;
}
else{
sscanf(te,"%lf", &c);
c*=flag;
calc(i);
// return 0;
continue;
}
}
i++;
if(str[i]=='('){
calc(i);
continue;
//return 0;
}
flag=1;
if(str[i]=='-') flag=-1;
i++;
int co=0;
for( ; str[i] != '('; i++){
te[co++] = str[i];
}
te[co++] = 0;
sscanf(te,"%lf", &c);
c*=flag;
calc(i);
}
return 0;
}
字符串处理
最新推荐文章于 2024-08-24 22:02:28 发布