展开全部
package Test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringBufferInputStream;
import java.io.StringReader;
import java.util.Scanner;
class Test {
private static Node firstList, secondList, resultList;
private static void input(Node head) throws Exception {
int a;
int b;
int i;
Node p = head;
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
// 读取一行信息
String input = reader.readLine();
// 以空格为分隔符e5a48de588b662616964757a686964616f31333332636331,转换成数组
String[] numbers = input.split(" ");
for(i=0;i
a = Integer.parseInt(numbers[i]);
b = Integer.parseInt(numbers[i+1]);
p.next = new Node(a, b);
p = p.next;
i+=2;
}
}
public static void main(String[] args) throws Exception {
firstList = new Node();
secondList = new Node();
resultList = new Node();
Node p=resultList;
System.out.println("输入第一个多项式");
input(firstList);
System.out.println("输入第二个不等式");
input(secondList);
while(firstList.next!=null&&secondList.next!=null){
if(firstList.next.zs>secondList.next.zs){
p.next=new Node(firstList.next.xs,firstList.next.zs);
p=p.next;
firstList=firstList.next;
}else if(firstList.next.zs
p.next=new Node(secondList.next.xs,secondList.next.zs);
p=p.next;
secondList=secondList.next;
}else{
p.next=new Node(firstList.next.xs+secondList.next.xs,firstList.next.zs);
p=p.next;
firstList=firstList.next;
secondList=secondList.next;
}
}
if(firstList!=null){
p.next=firstList.next;
}
if(secondList!=null){
p.next=secondList.next;
}
p=resultList;
while(p.next!=null){
System.out.print(p.next.xs+"x^"+p.next.zs+"+");
p=p.next;
}
System.out.println();
}
}public class Node {
public int xs;//系数
public int zs;//指数
public Node next=null;//指向下一个
public Node(int a,int b) {
xs=a;
zs=b;
}
public Node(){
}
}
答案
输入第一个多项式
5 4 3 2 1 1
输入第二个不等式
4 4 3 2 1 1
9x^4+6x^2+2x^1