码迷,mamicode.com
首页 > 其他好文 > 详细

02-线性结构1. 一元多项式求导 (25)

时间:2015-04-08 00:40:52      阅读:579      评论:0      收藏:0      [点我收藏+]

标签:


设计函数求一元多项式的导数。(注:xn(n为整数)的一阶导数为n*xn-1。)

输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。

输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是0,但是表示为“0 0”。

输入样例:
3 4 -5 2 6 1 -2 0
输出样例:
12 3 -10 1 6 0


1
import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStreamReader; 4 5 public class Main 6 { 7 public static void main(String[] args) throws IOException 8 { 9 BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); 10 String line=buf.readLine(); 11 String[] temp=line.split(" "); 12 int[][]A=new int[temp.length/2][2]; 13 for(int i=0;i<A.length;i++) 14 { 15 A[i][0]=Integer.parseInt(temp[2*i]); 16 A[i][1]=Integer.parseInt(temp[2*i+1]); 17 } 18 19 int[][]B=new int[temp.length/2][2]; 20 int j=0; 21 for(int i=0;i<A.length;i++) 22 { 23 if(A[i][1]==0) 24 continue; 25 B[j][0]=A[i][0]*A[i][1]; 26 B[j][1]=A[i][1]-1; 27 j++; 28 } 29 if(j==0) 30 System.out.println("0 0"); 31 else 32 { 33 for(int i=0;i<j-1;i++) 34 System.out.print(B[i][0]+" "+B[i][1]+" "); 35 System.out.println(B[j-1][0]+" "+B[j-1][1]); 36 } 37 38 } 39 }

 

02-线性结构1. 一元多项式求导 (25)

标签:

原文地址:http://www.cnblogs.com/qq1029579233/p/4401057.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!