洛谷 P5713、P5719、P5730、P5737题 题解(Java语言描述)

P5713

题目要求

P5713题目链接

在这里插入图片描述

AC代码(Java语言描述)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num  =scanner.nextInt();
        System.out.println((5*num < 3*num+11) ? "Local" : "Luogu");
        scanner.close();
    }
}

P5719

题目要求

P5719题目链接

在这里插入图片描述

AC代码(Java语言描述)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), k = scanner.nextInt(), counter1 = 0, counter2 = 0, sum1 = 0, sum2 = 0;
        for (int i = 1; i <= n; i++) {
            if (i % k == 0) {
                counter1++;
                sum1 += i;
            } else {
                counter2++;
                sum2 += i;
            }
        }
        scanner.close();
        System.out.printf("%.1f %.1f", ((double)sum1/counter1), ((double)sum2/counter2));
    }
}

P5730

题目要求

P5730题目链接

在这里插入图片描述

AC代码(Java语言描述)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        StringBuilder line1 = new StringBuilder();
        StringBuilder line2 = new StringBuilder();
        StringBuilder line3 = new StringBuilder();
        StringBuilder line4 = new StringBuilder();
        StringBuilder line5 = new StringBuilder();
        Scanner scanner = new Scanner(System.in);
        scanner.nextLine();
        char[] nums = scanner.nextLine().toCharArray();
        scanner.close();
        for (char c : nums) {
            switch (c) {
                case '0':
                    line1.append("XXX.");
                    line2.append("X.X.");
                    line3.append("X.X.");
                    line4.append("X.X.");
                    line5.append("XXX.");
                    break;
                case '1':
                    line1.append("..X.");
                    line2.append("..X.");
                    line3.append("..X.");
                    line4.append("..X.");
                    line5.append("..X.");
                    break;
                case '2':
                    line1.append("XXX.");
                    line2.append("..X.");
                    line3.append("XXX.");
                    line4.append("X...");
                    line5.append("XXX.");
                    break;
                case '3':
                    line1.append("XXX.");
                    line2.append("..X.");
                    line3.append("XXX.");
                    line4.append("..X.");
                    line5.append("XXX.");
                    break;
                case '4':
                    line1.append("X.X.");
                    line2.append("X.X.");
                    line3.append("XXX.");
                    line4.append("..X.");
                    line5.append("..X.");
                    break;
                case '5':
                    line1.append("XXX.");
                    line2.append("X...");
                    line3.append("XXX.");
                    line4.append("..X.");
                    line5.append("XXX.");
                    break;
                case '6':
                    line1.append("XXX.");
                    line2.append("X...");
                    line3.append("XXX.");
                    line4.append("X.X.");
                    line5.append("XXX.");
                    break;
                case '7':
                    line1.append("XXX.");
                    line2.append("..X.");
                    line3.append("..X.");
                    line4.append("..X.");
                    line5.append("..X.");
                    break;
                case '8':
                    line1.append("XXX.");
                    line2.append("X.X.");
                    line3.append("XXX.");
                    line4.append("X.X.");
                    line5.append("XXX.");
                    break;
                default:
                    line1.append("XXX.");
                    line2.append("X.X.");
                    line3.append("XXX.");
                    line4.append("..X.");
                    line5.append("XXX.");
                    break;
            }
        }
        int length = line1.length();
        System.out.println(line1.substring(0, length-1));
        System.out.println(line2.substring(0, length-1));
        System.out.println(line3.substring(0, length-1));
        System.out.println(line4.substring(0, length-1));
        System.out.println(line5.substring(0, length-1));
    }
}

P5737

题目要求

P5737题目链接

在这里插入图片描述

AC代码(Java语言描述)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int min = scanner.nextInt(), max = scanner.nextInt();
        scanner.close();
        int counter = 0;
        StringBuilder result = new StringBuilder();
        for (int i = min; i <= max; i++) {
            if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
                result.append(i).append(" ");
                counter++;
            }
        }
        System.out.println(counter + "\n" + result.toString().trim());
    }
}
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页