解题思路:
注意事项:
参考代码:
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 人评分
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:468 |
WU-陶陶摘苹果2 (C++代码)浏览:975 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:529 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:633 |
Minesweeper (C语言描述,蓝桥杯)浏览:1127 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:679 |
字符逆序 (C语言代码)浏览:460 |
第三届阿里中间件性能挑战赛-总决赛亚军比赛攻略浏览:1145 |
1231题解(注意理解“输入多个测试实例”)浏览:789 |
整除的尾数 (C语言代码)浏览:814 |