刷题(一)

简介: 刷题(一)

题目:

本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
 
如下的 
10
10 行数据,每行有 
10
10 个整数,请你求出它们的乘积的末尾有多少个零?
 
5650 4542 3554 473 946 4114 3871 9073 90 4329 
2758 7949 6113 5659 5245 7432 3051 4434 6704 3594 
9937 1173 6866 3397 4759 7557 3070 2287 1453 9899 
1486 5722 3135 1170 4014 5510 5120 729 2880 9019 
2049 698 4582 4346 4427 646 9742 7340 1230 7683 
5693 7015 6887 7381 4172 4341 2909 2027 7355 5649 
6701 6645 1671 5978 2704 9926 295 3125 3878 6785 
2066 4247 4800 1578 6652 4616 1113 6205 3264 2915 
3966 5291 2904 1285 2193 1428 2265 8730 9436 7074 
689 5510 8243 6114 337 4096 8199 7313 3685 211

代码:

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int[] nums = new int[100];
        int five=0;
        int two=0;
        for(int i=0;i<100;++i) {
            nums[i]=scan.nextInt();
            int t = nums[i];
            for(;t%2!=1;t/=2)
                two++;
            for(;t%5==0;t/=5)
                five++;
        }
        int result=five<two?five:two;
        System.out.println(result);
        scan.close();
    }
}

思路:影响最后结果的10有多少个就是由2和5决定的,这个题解的思路实在是太巧了👍(看题解的).

第二题:



public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long num = 0;
        long sum = 0;
        long n = scanner.nextLong();
        long []arr = new long[(int) n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = i+1; j <n; j++) {
                num = arr[i]*arr[j];
                sum = sum+num;
            }
 
        }
        System.out.println(sum);
    }
}//这个是错误的代码哈,只能运行30%,没想到还有这种要求
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        //定义一个数组
        Long [] arr = new Long[n];
        Long sum = 0l;
        //对数组赋值
        for( int i = 0 ; i < arr.length ; i++ ){
            arr[i] = sc.nextLong();
            sum += arr[i];  //对数组求和
        }
        //结果
        Long res = 0l;
        for( int i = 0 ; i < arr.length - 1 ; i++ ){
            //依次减去当前索引所指的数
            sum -= arr[i];
            //累加求和
            res += sum * arr[i];
        }
        System.out.println(res);
    }
}

思路:又是看题解的,因为用常规法时间复杂O(N2),所以行不通。

第三题:

小蓝正在学习一门神奇的语言,这门语言中的单词都是由小写英文字母组 成,有些单词很长,远远超过正常英文单词的长度。小蓝学了很长时间也记不住一些单词,他准备不再完全记忆这些单词,而是根据单词中哪个字母出现得最多来分辨单词。
 
现在,请你帮助小蓝,给了一个单词后,帮助他找到出现最多的字母和这 个字母出现的次数。
输入描述:
输入一行包含一个单词,单词只由小写英文字母组成。
对于所有的评测用例,输入的单词长度不超过 1000。
输出描述
输出两行,第一行包含一个英文字母,表示单词中出现得最多的字母是哪 个。如果有多个字母出现的次数相等,输出字典序最小的那个。
第二行包含一个整数,表示出现得最多的那个字母在单词中出现的次数。
输入输出样例
示例 1
输入
lanqiao
输出
a
2
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner =new Scanner(System.in);
        String s =scanner.nextLine();
        int[]array =new int[26];
        for (int i = 0; i < s.length(); i++) {
            array[s.charAt(i)-97]++;
        }
        char ch ='a';
        int max = 0;
        for (int i = 0; i < 26; i++) {
            if (array[i]>max){
                max = array[i];
                ch = (char)('a'+i);
            }
 
        }
        System.out.println(ch);
        System.out.println(max);
    }
}

思路:先定义一个数组对应26个字母的位置,然后找出数组中每个字母出现的次数对应在各个数组。题目说如果有多个字母出现的次数相等,输出字典序最小的那个,但是因为各个字母顺序已经从小到大排好了,所以不用担心,直接就可以了。

第四题:

import java.util.Scanner;
import java.lang.*;
 
public class Main {
    public static void main(String[] args) {
        double jige = 0;
        double you = 0;
        Scanner scanner =new Scanner(System.in);
        int a =scanner.nextInt();
        for (int i = 0; i < a; i++) {
            int b =scanner.nextInt();
            if (b>=60){
                jige+=1;
            }
            if (b>=85){
                you +=1;
            }
        }
        System.out.println(Math.round(jige / a*100)+"%");
        System.out.println(Math.round(you / a*100)+"%");
    }
}

思路:这里要注意的就是这个Math.round,我一开始又没看到😢😢.

第五题:

public class Main {
    public static void main(String[] args) {
        int count = 0;
        for (int i = 1; i <= 2020; i++) {
            String S = i+"";
            for (int j = 0; j < S.length(); j++) {
                if (S.charAt(j) == '2'){
                    count++;
                }
            }
        }
        System.out.println(count);
 
    }
}

思路:这一题的话转换成字符串然后一个个取出来比较是否=='2'就可以了。

好了,今天的博客就到此为止,如果哪里有遗漏,哪里有错误缺点,或者题目有其余解发或者更优解,希望大佬们能在评论区指正。还有还有就是大佬们都是怎么编排题目的,我是直接截图题目了,希望大佬能在评论区教教,感谢感谢

目录
相关文章
|
3天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8094 2
|
12天前
|
域名解析 人工智能 Linux
|
20天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
10610 13
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
6天前
|
人工智能 安全 网络安全
|
11天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1595 5
|
10天前
|
云安全 数据采集 人工智能
|
17天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2750 8
|
10天前
|
Web App开发 缓存 安全
巨魔商店 TrollStore 安装教程(2026):免电脑在线安装与全机型安装器矩阵_iOS巨魔安装
巨魔商店(TrollStore)是iOS 14–17.0(特定版本)的永久签名工具,无需越狱,利用CoreTrust漏洞实现IPA签名长期有效,彻底告别7天重签。支持免电脑在线安装(TrollHelperOTA),适配多机型/系统组合,开源免费,安全可控。(239字)
2674 0