C++ extract polynomial coefficients

前端 未结 5 1319
迷失自我
迷失自我 2021-01-26 01:38

So I have a polynomial that looks like this: -4x^0 + x^1 + 4x^3 - 3x^4
I can tokenize this by space and \'+\' into: -4x^0, x^1, 4x^3, -, 3x^4

How could I just get t

5条回答
  •  有刺的猬
    2021-01-26 02:20

    scan the string for an 'x', then go backward storing each character of the coefficient until you hit white space. eg:

    for (int i=0; i=0 && s[j]!=' '; --j)
                c = s[j] + c;
            cout << "coefficient: " << c << endl;
        }
    }
    

提交回复
热议问题