注册 登录
编程论坛 C++教室

编写一程序,实现方程式相加

问道炼心 发布于 2010-10-24 14:06, 654 次点击
编写一程序,实现方程式相加
例如:输入下面两个方程
12a+4b-5c=7
2a-8b+3c=6
相加后有:
14a-4b-2c=13
要求用字符数组实现
2 回复
#2
kspliusa2010-10-28 22:35
寻找对应项,对应项系数求和即可,不难!
#3
青青子惊2010-10-30 19:53
#include <string>
#include <vector>
#include <iostream>
using namespace std;
struct node
{
    int zhi;
    int xishu;
};
node p[3]={2,1,3,2,4,3};
node q[3]={2,1,0,2,3,3};

int main()
{
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(q[j].xishu==p[i].xishu)
                p[i].zhi+=q[j].zhi;
        }
    }
    for(int i=0;i<3;i++)
    {
        cout<<p[i].zhi<<endl;
    }
}
模拟了两个式子结构相同的, 1 2 3 就代表三个字母,懒得用字符比较了,,so 扩展,你懂的
1