杭电 OJ 1010-1019 Java解法(未更新完毕)

1010

1011

1012

先得到结果

然后面向结果输出结果即可

java 复制代码
import java.util.Scanner;

public class Main {

    static  double sum=0;

    public static void main(String[] args) {
       
        Scanner sc=new Scanner(System.in);

//        for (int i = 0; i < 10; i++) {
//                sum+=1.0/fac(i);
//            System.out.println(i+" "+String.format("%.9f",sum));
//        }

        System.out.println("n e");
        System.out.println("- -----------");
        System.out.println("0 1");
        System.out.println("1 2");
        System.out.println("2 2.5");
        System.out.println("3 2.666666667");
        System.out.println("4 2.708333333");
        System.out.println("5 2.716666667");
        System.out.println("6 2.718055556");
        System.out.println("7 2.718253968");
        System.out.println("8 2.718278770");
        System.out.println("9 2.718281526");
    }

    public static double fac(int x){
        int result=1;
        for (int i1 = 1; i1 <= x; i1++) {
            result*=i1;
        }
        return result;
    }
}

1013

开long不行 得开大数

java 复制代码
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            BigInteger n = sc.nextBigInteger();
            if (n.equals(BigInteger.ZERO)) return;
            BigInteger ans = n;
            while (ans.compareTo(BigInteger.TEN) >= 0) {
                BigInteger k = ans;
                ans = BigInteger.ZERO;
                while (k.compareTo(BigInteger.ZERO) > 0) {
                    ans = ans.add(k.mod(BigInteger.TEN));
                    k = k.divide(BigInteger.TEN);
                }
            }
            System.out.println(ans);
        }
    }
}

1014

1015

1016

1017

1018

直接取对数

java 复制代码
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int j = 0; j < n; j++) {
            double sum = 0.0;
            int x = scanner.nextInt();
            for (int i = 1; i <= x; i++) {
                sum += Math.log10(i);
            }
            System.out.println((int) (sum) + 1);
        }
    }
}

1019

线性表遍历

java 复制代码
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        while (m-- > 0) {
            int n = scanner.nextInt();
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = scanner.nextInt();
            }
            for (int i = 0; i < n - 1; i++) {
                x[i + 1] = run(x[i], x[i + 1]);
            }
            System.out.println(x[n - 1]);
        }
    }
  public static int run(int x, int y) {
        int i, s;
        for (i = Math.min(x, y); i >= 1; i--) {
            if (x % i == 0 && y % i == 0) {
                break;
            }
        }
        s = (x / i) * y;
        return s;
    }
}
相关推荐
风象南14 分钟前
SpringBoot离线应用的5种实现方式
java·spring boot·后端
o独酌o19 分钟前
鼠标的拖动效果
开发语言·javascript
张哈大28 分钟前
【 java 集合知识 第二篇 】
java·开发语言·笔记·哈希算法
潮流coder1 小时前
mybatis的if判断==‘1‘不生效,改成‘1‘.toString()才生效的原因
java·tomcat·mybatis
2401_876907521 小时前
IEC 61347-1:2015 灯控制装置安全标准详解
大数据·数据结构·人工智能·算法·安全·学习方法
T.Ree.1 小时前
【数据结构】_排序
数据结构·算法·排序算法·排序
二进制的Liao1 小时前
【数据分析】什么是鲁棒性?
运维·论文阅读·算法·数学建模·性能优化·线性回归·负载均衡
青临的踩坑之路1 小时前
Docker + Nginx + Logrotate 日志管理与轮换实践
java·开发语言
じ☆ve 清风°3 小时前
JavaScript 原型与原型链:深入理解 __proto__ 和 prototype 的由来与关系
开发语言·javascript·原型模式
这儿有一堆花3 小时前
比特币:固若金汤的数字堡垒与它的四道防线
算法·区块链·哈希算法