zoukankan      html  css  js  c++  java
  • Java实现 蓝桥杯VIP 算法提高 复数求和

    算法提高 复数求和
    时间限制:1.0s 内存限制:512.0MB
    从键盘读入n个复数(实部和虚部都为整数)用链表存储,遍历链表求出n个复数的和并输出。
    样例输入:
    3
    3 4
    5 2
    1 3
    样例输出:
    9+9i
    样例输入:
    7
    1 2
    3 4
    2 5
    1 8
    6 4
    7 9
    3 7
    样例输出:
    23+39i

    import java.util.LinkedList;
    import java.util.List;
    import java.util.Scanner;
    
    
    public class 复数求和 {
    	public static void main(String[] args) {
    		Scanner sc=new Scanner(System.in);
    		List<Integer> shibu=new LinkedList<Integer>();
    		List<Integer> xubu=new LinkedList<Integer>();
    		int n=sc.nextInt();
    		int i=0;
    		while(i<n){
    			shibu.add(sc.nextInt());
    			xubu.add(sc.nextInt());
    			i++;
    		}
    		int sumofShibu=0;
    		int sumOfxuBu=0;
    		for(i=0;i<shibu.size();i++){
    			sumofShibu+=shibu.get(i);
    			sumOfxuBu+=xubu.get(i);
    		}
    		if(sumOfxuBu>0){
    			System.out.println(sumofShibu+"+"+sumOfxuBu+"i");
    		}else{
    			System.out.println(sumofShibu+""+sumOfxuBu+"i");
    		}
    	}
    
    }
    
    
  • 相关阅读:
    怎么删除json 键值对
    解决html 图片缓存问题
    美工常用的网站分享
    小程序授权页面
    BitMap原理
    css页面加载动画
    可能这些是你想要的H5软键盘兼容方案
    关于范式 :1NF 2NF 3NF等
    Python3学习DAY4
    DTD相关
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13078847.html
Copyright © 2011-2022 走看看