洛谷P1151、P1200、P1420、P1634题解(Java语言描述)

P1151题目要求

P1151题目链接

在这里插入图片描述
在这里插入图片描述

P1151题解

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int count = 0;
        Scanner scan = new Scanner(System.in);
        int K = scan.nextInt();
        if (K > 0 && K < 3000) {
            for (int i = 10000; i<=30000; i++) {
                int a = i/10000;
                int b = (i - a*10000)/1000;
                int c = (i - a*10000 - b*1000)/100;
                int d = (i - a*10000 - b*1000 - c*100)/10;
                int e = (i - a*10000 - b*1000 - c*100 - d*10);
                int sub1 = a*100 + b*10 + c;
                int sub2 = b*100 + c*10 + d;
                int sub3 = c*100 + d*10 + e;
                if (sub1%K==0 && sub2%K==0 && sub3%K==0) {
                    System.out.println(i);
                    count++;
                }
            }
            if (count==0) {
                System.out.println("No");
            }
        }
        scan.close();
    }
}

P1200题目要求

P1200题目链接

在这里插入图片描述
在这里插入图片描述

P1200题解

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String star = scanner.nextLine();
        String ufo = scanner.nextLine();
        char[] starArr = star.toCharArray();
        char[] ufoArr = ufo.toCharArray();
        int starInt = 1;
        for (char c : starArr) {
            starInt *= (c-64);
        }
        int ufoInt = 1;
        for (char c : ufoArr) {
            ufoInt *= (c-64);
        }
        if (starInt % 47 == ufoInt % 47) {
            System.out.println("GO");
        } else {
            System.out.println("STAY");
        }
        scanner.close();
    }

}


P1420题目要求

P1420题目链接

在这里插入图片描述

P1420题解

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int max = 1;
        int tmp = 1;
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        if (n >= 1 && n <= 10000) {
            int[] number = new int[n+1];
            for (int i = 0; i < n; i++) {
                number[i] = scan.nextInt();
            }
            for (int i = 0; i < n; i++) {
                if (number[i+1] - number[i] == 1)
                    tmp++;
                else
                    tmp = 1;
                if (tmp > max)
                    max = tmp;
            }
        }
        System.out.println(max);
        scan.close();
    }
}

P1634题目要求

P1634题目链接

在这里插入图片描述

P1634题解

import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void  main(String[] args) {
        ArrayList<Integer> collector= new ArrayList<>();
        int x = 0, y = 0, a = 0, b = 0, c = 0;
        int[] count = new int[10];

        Scanner scan = new Scanner(System.in);
        x = scan.nextInt();
        y = scan.nextInt();

        String stry = y + " ";
        int len2 = stry.length()-1;

        for (int i = x; i <= y; i++) {
            c = i;
            for (int j = len2-1; j >= 0; j--) {
                a = (int)Math.pow(10, j);
                b = c/a;
                c %= a;
                collector.add(b);
            }
        }

        for (int i : collector) {
            switch (i) {
                case 0:
                    count[0] ++;
                    break;
                case 1:
                    count[1] ++;
                    break;
                case 2:
                    count[2] ++;
                    break;
                case 3:
                    count[3] ++;
                    break;
                case 4:
                    count[4] ++;
                    break;
                case 5:
                    count[5] ++;
                    break;
                case 6:
                    count[6] ++;
                    break;
                case 7:
                    count[7] ++;
                    break;
                case 8:
                    count[8] ++;
                    break;
                case 9:
                    count[9] ++;
                    break;
                default:
                    System.err.println("Error!");
            }
        }

        for (int i : count) {
            System.out.print(i + " ");
        }

        scan.close();
    }

}


都是以前写的,如果lj,还请见谅

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星拱北辰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值