文章
28
粉丝
230
获赞
23
访问
241.9k
#include<iostream>
#include<ctype.h>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
double a, b, c;
string s;
int main(){
while (cin >> s){
a = b = c = 0;
if (s[0] != '-'&&s[0] != '+')s = '+' + s;
int pos = s.find('=');
if (s[pos + 1] != '+'&&s[pos + 1] != '-')s.insert(pos + 1, 1, '+');
int i = 0,size = s.size();
while (i < size){
int j = i++;
while (i < size&&isdigit(s[i]))i++;
int t;
if (i == j + 1){
t = s[j] == '+' ? 1 : -1;
}
else {
t = atoi(s.substr(j, i - j).c_str());
}
if (i == size || s[i] !='x')c += (j>pos?-1:1)*t;
else {
if (i + 1 < size && s[i + 1] == '^')a += (j>pos?-1:1)*t;
...
登录后发布评论
暂无评论,来抢沙发