https://www.luogu.org/problemnew/show/P1022

服了,居然还有+0.000和-0.000的不同,真的服了。

#include<bits/stdc++.h>
using namespace std;
#define ll long long //a1x+b1=a2x+b2
double a1,b1,a2,b2; int main(){
string s;
string s1;
string s2;
while(cin>>s){
int n=s.length(); char c; for(int i=;i<n;i++){
if(s[i]=='='){
s1=s.substr(,i);
s2=s.substr(i+,n);
break;
}
} int n1=s1.length();
int n2=s2.length(); //cout<<s1<<" "<<s2<<endl; double cur=;
double flag=;
for(int i=;i<n1;i++){
if(s1[i]=='-'){
b1+=flag*cur;
flag=-;
cur=;
}
else if(s1[i]=='+'){
b1+=flag*cur;
flag=+;
cur=;
}
else if(isalpha(s1[i])){
c=s1[i];
if(cur==)
cur=;
a1+=flag*cur;
cur=;
}
else{
cur*=;
cur+=(s1[i]-'');
}
} b1+=flag*cur;
flag=;
cur=; //cout<<a1<<" "<<b1<<endl; for(int i=;i<n2;i++){
if(s2[i]=='-'){
b2+=flag*cur;
flag=-;
cur=;
}
else if(s2[i]=='+'){
b2+=flag*cur;
flag=+;
cur=;
}
else if(isalpha(s2[i])){
c=s2[i];
if(cur==)
cur=;
a2+=flag*cur;
flag=+;
cur=;
}
else{
cur*=;
cur+=(s2[i]-'');
}
} b2+=flag*cur;
flag=;
cur=; //cout<<a2<<" "<<b2<<endl; //ax=b
double a=a1-a2;
double b=b2-b1; double ans=b/a;
if(fabs(ans)<1e-)
ans=;
printf("%c=%.3f\n",c,ans);
} }
05-26 23:20