We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#include <string> #include <vector> #include <sstream> #include <iostream> using namespace std; bool isLinear(string str) { for (char c : str) { if (c == 'x') { return true; } } return false; } int getNumber(string str) { int result = 0; for (char c : str) { if (isdigit(c)) { result = result * 10 + (c - '0'); } } return result; } string solution(string polynomial) { int linear = 0; int num = 0; string code; stringstream ss(polynomial); while (ss >> code) { if (code != "+") { if (isLinear(code)) { linear += getNumber(code); if (code.length() == 1) { linear++; } } else { num += getNumber(code); } } } string linearStr = ""; if (linear == 1) { linearStr = "x"; } else { linearStr = to_string(linear) + "x"; } if (linear != 0 && num != 0) { return linearStr + " + " + to_string(num); } else if (linear != 0) { return linearStr; } else { return to_string(num); } }
The text was updated successfully, but these errors were encountered:
fkdl0048
No branches or pull requests
The text was updated successfully, but these errors were encountered: