贺州学院ivy


私信TA

用户名:Livy

访问量:21470

签 名:

好好学习,天天向上,汝何秀?

等  级
排  名 132
经  验 7408
参赛次数 5
文章发表 25
年  龄 0
在职情况 学生
学  校 贺州学院
专  业 软件工程

  自我简介:

假猪套天下第一

解题思路:

其实我感觉这题是有问题的

像 输入 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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区