杭电 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;
    }
}
相关推荐
野犬寒鸦5 分钟前
力扣hot100:旋转图像(48)(详细图解以及核心思路剖析)
java·数据结构·后端·算法·leetcode
墨染点香7 分钟前
LeetCode 刷题【61. 旋转链表】
算法·leetcode·职场和发展
金融数据出海8 分钟前
黄金金融期货数据API对接技术文档
开发语言·金融·github
七夜zippoe13 分钟前
AI+Java 守护你的钱袋子!金融领域的智能风控与极速交易
java·人工智能·金融
Suckerbin20 分钟前
DarkHole: 2靶场渗透
笔记·安全·web安全·网络安全
诗书画唱24 分钟前
【前端教程】JavaScript 实现图片鼠标悬停切换效果与==和=的区别
开发语言·前端·javascript
岁忧26 分钟前
(LeetCode 面试经典 150 题) 200. 岛屿数量(深度优先搜索dfs || 广度优先搜索bfs)
java·c++·leetcode·面试·go·深度优先
一枝小雨33 分钟前
【OJ】C++ vector类OJ题
数据结构·c++·算法·leetcode·oj题
一枝小雨34 分钟前
【C++】Vector完全指南:动态数组高效使用
开发语言·c++·笔记·vector·学习笔记·std库
诗书画唱43 分钟前
【前端教程】JavaScript DOM 操作实战案例详解
开发语言·前端·javascript