1010 一元多项式求导 (25 分)——数学

1010 一元多项式求导 (25 分)——数学

设计函数求一元多项式的导数。

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

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

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

public class _1010 {
//	用BufferedReader不能通过pat官网的部分测试点,但是牛客网上面可以全部通过,原因未知
//	static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//	public static void main(String[] args) throws IOException {
//		String[] tmp = in.readLine().split(" ");
//		boolean flag = false;
//		for (int i = 0; i < tmp.length; i = i + 2) {
//			int m = Integer.valueOf(tmp[i]);
//			int n = Integer.valueOf(tmp[i + 1]);
//			if (n * m != 0) {
//				if (flag == false) {
//					flag = true;
//				} else {
//					System.out.print(" ");
//				}
//				System.out.print(m * n + " " + (n - 1));
//			}
//		}
//		if (!flag) {
//			System.out.print("0 0");
//		}
//	}
static Scanner in=new Scanner(System.in);
public static void main(String[] args) {
	boolean flag=false;		//用来确定是不是“零多项式”
	while(in.hasNext()) {
		int m=in.nextInt();
		int n=in.nextInt();
		if (n * m != 0) {
			if (flag == false) {
				flag = true;
			} else {
				System.out.print(" ");
			}
			System.out.print(m * n + " " + (n - 1));
		}
	}
	if (!flag) {
		System.out.print("0 0");
	}
}
}

猜你喜欢

转载自blog.csdn.net/qq_40908515/article/details/86543054