解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
//输入n个数
int arr [] = new int[n];
String res = "";
for (int i=0;i<n;i++){
arr[i] = sc.nextInt();
//对arr[i]分 三种情况
if (arr[i]<0) {
//情况一:小于0
if (arr[i] == -1) {
//+/-1都要进行特殊处理
res = res + "-x^" + (n - i);
} else {
res = res + "-" + Math.abs(arr[i]) + "x^" + (n - i);
}
}
else if (arr[i]>0){
//情况二:大于0
if (arr[i] == 1) {
//+/-1都要进行特殊处理
res = res + "+x^" + (n - i);
} else {
res = res + "+" + arr[i] + "x^" + (n - i);
}
}
else{
//情况三:为0则直接跳过本轮循环
continue;
}
}
System.out.println(res.substring(1,res.length()-2));
sc.close();
/*
6
1 0 3 4 -2 2
*/
}
}
0.0分
0 人评分
C语言训练-求矩阵的两对角线上的元素之和 (C语言代码)浏览:3394 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:495 |
【亲和数】 (C语言代码)浏览:859 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:524 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:639 |
简单的a+b (C语言代码)浏览:577 |
The 3n + 1 problem (C语言代码)浏览:553 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:834 |
出圈】指针malloc版浏览:355 |
分糖果 (C语言代码)浏览:920 |