解题思路:
其实我感觉这题是有问题的
像 输入 5
0 0 1 0 0 0
输出是 +x^3也给过.......我也是醉了....
注意事项:
参考代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
int n,c;
cin >> n;
int a[150];
a[0] = 1;
for (int i = n; i >= 1; i--){
cin >> a[i];
}
cin >> c;//常数项
int s = n;
while (s){
if (s == n){
if (a[s] == 0){}
else if (a[s] == 1)cout << "x^" << s;
else if (a[s] == -1)cout << "-x^" << s;
else cout << a[s] << "x^" << s;
}
else{
if (a[s] == 0){}
else if (a[s] == 1){
cout << "+x";
if (s != 1)cout << "^" << s;
}
else if (a[s] == -1){
cout << "-x";
if (s != 1)cout << "^" << s;
}
else if (a[s] < 0){
cout << a[s] << "x";
if (s != 1)cout << "^" << s;
}
else if (a[s]>1){
cout << "+" << a[s] << "x";
if (s != 1)cout << "^"<<s;
}
}
s--;
}
if (c >= 1) cout<< "+"<<c << endl;
if (c < 0)cout << c << endl;
system("pause");
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:531 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:507 |
WU-蓝桥杯算法提高VIP-交换Easy (C++代码)浏览:1119 |
wu-淘淘的名单 (C++代码)浏览:1339 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:937 |
WU-整数平均值 (C++代码)浏览:1245 |
1014题解浏览:485 |
A+B for Input-Output Practice (VI) (C语言代码)浏览:558 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:683 |
C二级辅导-进制转换 (C语言代码)浏览:660 |