解题思路:
其实我感觉这题是有问题的
像 输入 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语言代码)浏览:597 |
C语言训练-排序问题<1> (C++代码)浏览:589 |
printf基础练习2 (C语言代码)浏览:644 |
用筛法求之N内的素数。 (C++代码)浏览:692 |
Cylinder (C语言描述+详细分析)浏览:3263 |
简单的a+b (C语言代码)浏览:414 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:582 |
字符串的输入输出处理 (C语言代码)浏览:985 |
大神老白 (C语言代码)浏览:600 |
C语言训练-自守数问题 (C语言代码)浏览:740 |