#include <iostream> #include <cmath> using namespace std; int main() { int a, b, c; cin…
- User
#include #include using namespace std;
int main() { int a, b, c; cin >> a >> b >> c;
string result = “”;
if (a == 0 && b == 0 && c == 0) { result = "0"; } else { if (a != 0) { result += to_string(a); } if (b != 0) { if (abs(b) != 1) { result += (b > 0) ? "+" : "-"; result += to_string(abs(b)); } else if (b < 0) { result += "-"; } result += "x"; } if (c != 0) { if (abs(c) != 1) { result += (c > 0) ? "+" : "-"; result += to_string(abs(c)); } else if (c < 0) { result += "-"; } result += "y"; } }
if (!result.empty() && result[0] == '+'') { // удаление лишнего знака “+” result.erase(0, 1); }
cout << result << endl;
return 0; } исправь
- Assistant
#include #include // добавляем заголовочный файл для работы со строками #include using namespace std;
int main() { int a, b, c; cin >> a >> b >> c;
string result = ""; if (a == 0 && b == 0 && c == 0) { result = "0"; } else { if (a != 0) { result += to_string(a); // преобразование числа в строку и добавление к результату } if (b != 0) { if (abs(b) != 1) { result += (b > 0) ? "+" : "-"; result += to_string(abs(b)); } else if (b < 0) { result += "-"; } result += "x"; } if (c != 0) { if (abs(c) != 1) { result += (c > 0) ? "+" : "-"; result += to_string(abs(c)); } else if (c < 0) { result += "-"; } result += "y"; } } if (!result.empty() && result[0] == '+') { // проверка на наличие лишнего знака “+” result.erase(0, 1); // удаление первого символа (лишнего “+”) } cout << result << endl; return 0;}