文章
13
粉丝
386
获赞
2
访问
64.9k
因为最高二次方,所以只需要分开判断即可
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
using namespace std;
int main(){
string str;
int a1 = 0, b1 = 0, c1 = 0; //左边系数
int a2 = 0, b2 = 0, c2 = 0; //右边系数
while(cin >> str){
int len = str.size();
bool right = false; //判断等式左右
bool Symbol = true; //+号为true,-号为false
int temp = 0;
for(int i = 0; i < len; i++){
if(!right){ //等式左边
if(str[i] == '='){
if(temp != 0){
c1 = temp;
if(!Symbol) c1 = -c1;
temp = 0;
}
right = true;
Symbol = true;
}
else if(isdigit(str[i])) temp = 10 * temp + str[i] - '0';
else if(str[i] == '+' || str[i] == '-') Symbol = str[i] ...
登录后发布评论
暂无评论,来抢沙发