Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
84022 sh25_shenpy 多项式输出 C++ 通过 0 MS 252 KB 1170 2026-02-05 16:24:50

Tests(10/10):


#include <iostream> #include <vector> #include <string> using namespace std; int main() { int n; cin >> n; vector<int> coefficients(n + 1); for (int i = 0; i <= n; ++i) { cin >> coefficients[i]; } vector<string> terms; for (int i = 0; i <= n; ++i) { int power = n - i; int coeff = coefficients[i]; if (coeff == 0) continue; string term; // 处理符号 if (coeff > 0) { if (!terms.empty()) { term += "+"; } } else { term += "-"; } // 处理系数绝对值 int abs_coeff = abs(coeff); if (abs_coeff != 1 || power == 0) { term += to_string(abs_coeff); } // 处理指数部分 if (power > 1) { term += "x^" + to_string(power); } else if (power == 1) { term += "x"; } terms.push_back(term); } // 拼接所有项 string result; for (const string& term : terms) { result += term; } cout << result << endl; return 0; }


测评信息: