解题思路:
注意事项:
参考代码:
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语言代码)浏览:508 |
模拟计算器 (C语言代码)浏览:882 |
【偶数求和】 (C++代码)浏览:702 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:634 |
WU-输入输出格式练习 (C++代码)浏览:1078 |
【绝对值排序】 (C语言代码)浏览:820 |
1642题解浏览:710 |
K-进制数 (C语言描述,蓝桥杯)浏览:925 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:505 |
字符串比较 (C语言代码)浏览:680 |