48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include <iostream>
|
|
#include <iomanip>
|
|
#include <string>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
int main() {
|
|
#ifdef local
|
|
freopen("pro.in", "r", stdin);
|
|
#endif // ifdef local
|
|
string s;
|
|
cin >> s;
|
|
int A = 0, B = 0; // Ax+B=0
|
|
bool is_right_side = false;
|
|
char variable_name;
|
|
int cur = 0, flg = 1;
|
|
for (int i = 0; i < s.size(); i++) {
|
|
if (('0' <= s[i]) && (s[i] <= '9')) {
|
|
cur = cur * 10 + s[i] - '0';
|
|
} else if (s[i] == '=') {
|
|
B += cur * flg;
|
|
cur = 0;
|
|
flg = 1;
|
|
is_right_side = true;
|
|
} else if (('a' <= s[i]) && (s[i] <= 'z')) {
|
|
if (((i - 1 >= 0) && !(('0' <= s[i - 1]) && (s[i - 1] <= '9'))) ||
|
|
(i == 0)) cur = 1;
|
|
variable_name = s[i];
|
|
if (!is_right_side) A += cur * flg;
|
|
else A -= cur * flg;
|
|
cur = 0;
|
|
flg = 1;
|
|
} else {
|
|
if ((i - 1 >= 0) && ('0' <= s[i - 1]) && (s[i - 1] <= '9')) {
|
|
if (!is_right_side) B += cur * flg;
|
|
else B -= cur * flg;
|
|
cur = 0;
|
|
flg = 1;
|
|
if (s[i] == '-') flg = -1;
|
|
} else {
|
|
if (s[i] == '-') flg *= -1;
|
|
}
|
|
}
|
|
}
|
|
B -= cur * flg;
|
|
double res = -double(B) / A;
|
|
cout << variable_name << "=" << fixed << setprecision(3) << res << endl;
|
|
return 0;
|
|
} |