美文网首页
第4章编程题

第4章编程题

作者: 我是阿喵酱 | 来源:发表于2018-02-04 16:38 被阅读0次

    多项式加法

    import java.util.Scanner;
    
    public class HelloWorld {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int []a=new int[101];
            for(;;){
            int b = in.nextInt();
            int c = in.nextInt();
            a[b] = c;
            if(b==0)break;
            }
            for(;;){
            int b = in.nextInt();
            int c = in.nextInt();
            a[b] += c;
            if(b==0)break;
            }
            for(int i=100;i>=0;i--){
                if(a[i]!=0){
                    System.out.print(a[i]);
                    if(i>=1)System.out.print("x");
                    if(i>1)System.out.print(i);
                    if(i!=0)System.out.print("+");
                }
            }
    
        }
    }
    

    相关文章

      网友评论

          本文标题:第4章编程题

          本文链接:https://www.haomeiwen.com/subject/hkcekxtx.html