The 14th Blue Bridge Cup Competition - Day 9 of Real Questions Training

Table of contents

The first problem: different substrings

topic description

operating limit

topic analysis

topic code

Question 2: Word Analysis 

topic description

enter description

output description

Input and output samples

operating limit

topic analysis

topic code

 Question 3: Paper Size

Problem Description

input format

output format

Sample input 1

Sample output 1

Sample input 2

Sample output 2

operating limit

topic code


The first problem: different substrings

topic description

This question is a fill-in-the-blank question. After calculating the result, use the output statement in the code to output the filled result.

A non-empty substring of a string refers to a string of consecutive characters whose length is at least 11. For example, the string aaab has non-empty substrings a, b, aa, ab, aaa, aab, aaab, a total of 77. Note that in the calculation, only the number of essentially different strings is counted.

Excuse me, how many different non-empty substrings are there in the string 01001100010100010100110001010001?

operating limit

  • Maximum running time: 1s
  • Maximum running memory: 256M

topic analysis

First split the string and then add it to the hashset collection (the elements in the collection are not repeated)

topic code

import java.util.HashSet;

public class 不同子串 {
    public static void main(String[] args) {
        HashSet<String> strings = new HashSet<>();
        String s="0100110001010001";
        for (int i = 0; i < s.length(); i++) {
            for (int j = i+1; j <= s.length(); j++) {
                String temp = s.substring(i,j);
                strings.add(temp);
            }
        }
        System.out.println(strings.size());
    }
}

Question 2: Word Analysis 

topic description

Xiaolan is learning a magical language. The words in this language are all composed of lowercase English letters, and some words are very long, far exceeding the length of normal English words. Xiaolan couldn't remember some words after studying for a long time. He planned not to memorize these words completely, but to distinguish words according to which letter appeared the most in the word.

Now, please help Xiaolan. After giving a word, help him find the letter that appears the most and the number of times this letter appears.

enter description

Enter a line containing a word, and the word is only composed of lowercase English letters.

For all evaluation cases, the input word length does not exceed 1000.

output description

Output two lines, the first line contains an English letter, indicating which letter appears most frequently in the word. If there are multiple letters with the same number of occurrences, output the one with the smallest lexicographical order.

The second line contains an integer representing the number of occurrences of the most frequent letter in the word.

Input and output samples

Example 1

enter

lanqiao

output

a
2

Example 2

enter

longlonglongistoolong

output

o
6

operating limit

  • Maximum running time: 1s
  • Maximum running memory: 256M

topic analysis

Note that for this question, the array must be copied first and then sorted on the original array 

topic code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class 单词分析 {
    public static void main(String[] args) throws IOException {
        BufferedReader ins = new BufferedReader(new InputStreamReader(System.in));
        char[] chars = ins.readLine().toCharArray();
        int[] arr = new int[26];
        for (int i = 0; i < chars.length; i++) {
            arr[chars[i]-'a']++;
        }
        int[] arr2 = Arrays.copyOf(arr, 26);
        Arrays.sort(arr);
        int max = arr[25];
        for (int i = 0; i < arr.length; i++) {
            if (arr2[i]==max){
                System.out.println((char)(i+'a'));
                System.out.println(max);
                break;
            }
        }
    }
}

 Question 3: Paper Size

Problem Description

In the ISO international standard, the size of A0 paper is defined as 1189mm × × 841mm. After folding the A0 paper in half along the long side, it becomes A1 paper with a size of 841mm × × 594mm. During the process of folding in half, the length is directly trimmed (during actual cutting may be damaged). Fold A1 paper in half along the long side to A2 paper, and so on.

Enter the name of the paper, please output the size of the paper.

input format

Enter a line containing a string indicating the name of the paper, which must be one of A0, A1, A2, A3, A4, A5, A6, A7, A8, and A9.

output format

Output two lines, each line contains an integer, which in turn represents the length of the long side and the short side.

Sample input 1

A0

Sample output 1

1189
841

Sample input 2

A1

Sample output 2

841
594

operating limit

  • Maximum running time: 1s
  • Maximum running memory: 512M

topic code

import java.util.Scanner;

public class 纸张尺寸 {
    public static void main(String[] args) {
        int cd = 1189;
        int kd = 841;
        Scanner sca = new Scanner(System.in);
        String[] split = sca.next().split("");
        int a = Integer.parseInt(split[1]);
        for (int i = 0; i < a; i++) {
            int max = Math.max(cd, kd);
            if (max == cd) {
                cd = cd / 2;
            } else
                kd = kd / 2;
        }
        System.out.println(Math.max(cd,kd));
        System.out.println(Math.min(cd,kd));
    }
}

Guess you like

Origin blog.csdn.net/weixin_61082895/article/details/129798934