| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 91015 | sh25_zhangjiajia | 多项式输出 | C++ | 通过 | 0 MS | 264 KB | 1108 | 2026-06-12 14:55:32 |
#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; }