2021 The 12th Blue Bridge Cup javaB group

test questions A: Integer range
test questions B: Pure prime number
test questions C: Full date
test questions D: Minimum weight
test questions E: Capitalize
test questions F: 123
test questions G: Sum and product
test questions H: Chocolates
test questions I: Flip bracket sequence
test questions J: XOR triangle

test questions A: Integer range
Total score of this question :5 branch
【 Problem description 】
   use 8 Bit binary ( One byte ) To represent a nonnegative integer , The minimum value represented is 0, What is the maximum value that can be expressed in general ?

【 Answer submission 】
This is a question to fill in the blanks , You just need to calculate the results and submit them . The result of this question is an integer , Only fill in this integer when submitting the answer , If you fill in extra content, you will not be able to score .

answer :255

test questions B: Pure prime number
Total score of this question :5 branch
【 Problem description 】

If a positive integer has only 1 And itself , Is called a prime number ( Also known as prime ).
   The first few prime numbers are :2,3,5,7,11,13,17,19,23,29,31,37….

   If all decimal places of a prime number are prime numbers , We call it a pure prime number . for example :2,3,5,7,23,37 Are pure prime numbers , and 11,13,17,19,29,31 Not a prime number . of course 1,4,35 Nor is it a pure prime number .
   Excuse me? , stay 1 reach 20210605 in , How many prime numbers are there ?

【 Answer submission 】
This is a question to fill in the blanks , You just need to calculate the results and submit them . The result of this question is an integer , Only fill in this integer when submitting the answer , If you fill in extra content, you will not be able to score .

answer :1903

test questions C: Full date
Total score of this question :10 branch
【 Problem description 】

If the sum of the numbers in a date is a complete square , Is called a full date .
   for example :2021 year 6 month 5 The sum of the figures of the day is 2 + 0 + 2 + 1 + 6 + 5 =
16, and 16 Is a perfect square number , It is 4 Square of . therefore 2021 year 6 month 5 Day is a full date .
   for example :2021 year 6 month 23 The sum of the figures of the day is 2 + 0 + 2 + 1 + 6 + 2 + 3 =
16, Is a perfect square number . therefore 2021 year 6 month 23 Day is also a full date .
   Excuse me? , from 2001 year 1 month 1 Day arrives 2021 year 12 month 31 Japan China , How many full dates are there ?

【 Answer submission 】
This is a question to fill in the blanks , You just need to calculate the results and submit them . The result of this question is an integer , Only fill in this integer when submitting the answer , If you fill in extra content, you will not be able to score .

answer :977

test questions D: Minimum weight
Total score of this question :10 branch
【 Problem description 】

For a rooted binary tree T, Xiaolan defines the weights of nodes in this tree W(T) as follows :
   The weight of the empty subtree is 0.
   If a node v Left subtree L, Right subtree R, Respectively C(L) and C® Nodes , be :
    W(v) = 1 + 2W(L) + 3W® +(C(L))2C®.
   The weight of the tree is defined as the weight of the root node of the tree .
   Xiaolan wants to know , For a tree with 2021 Binary tree with two nodes , What is the minimum possible weight of the tree ?

【 Answer submission 】
This is a question to fill in the blanks , You just need to calculate the results and submit them . The result of this question is an integer , Only fill in this integer when submitting the answer , If you fill in extra content, you will not be able to score .

answer :______

test questions E: Capitalize
time limit : 1.0s   Memory limit : 512.0MB   Total score of this question :15 branch
【 Problem description 】

Give a string that contains only uppercase and lowercase letters , Please convert all lowercase letters into uppercase letters and output the string .

【 Input format 】
The input line contains a string
【 Output format 】
Output string converted to uppercase .
【 sample input 1】
LanQiao
【 sample output 1】
LANQIAO
【 Scale and agreement of evaluation cases 】
For all profiling cases , The length of the string does not exceed 100.

Method 1 : use java of String Class's own conversion case toUpperCase() method .
import java.util.Scanner; public class Main { public static void main(String[]
args) { Scanner input = new Scanner(System.in); String a = input.next(); String
b= a.toUpperCase(); System.out.println(b); } }
Method 2 :
import java.util.*; public class Main { public static void main(String[] args)
{ Scanner input = new Scanner(System.in); String a = input.next(); String daxie=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String xiaoxie="abcdefghijklmnopqrstuvwxyz"; int
len=a.length(); for(int i=0;i<len;i++) { for(int j=0;j<26;j++) { if(a.charAt(i)
==daxie.charAt(j)) { System.out.print(daxie.charAt(j)); break; } else if(a.
charAt(i)==xiaoxie.charAt(j)) { System.out.print(daxie.charAt(j)); break; } } }
} }
test questions F: 123
time limit : 5.0s   Memory limit : 512.0MB   Total score of this question :15 branch
【 Problem description 】

Xiaolan found an interesting sequence , The first few items of this series are as follows :
    1, 1, 2, 1, 2, 3, 1, 2, 3, 4, …
   Xiaolan found , Before this sequence 1 Item is an integer 1, next 2 Item is an integer 1 to 2, next 3 Item is an integer 1 to 3, next 4 Item is an integer 1 to 4, And so on .
   Xiaolan wants to know , In this sequence , What is the sum of successive segments .

【 Input format 】
The first line of input contains an integer T, Indicates the number of queries .
next T that 's ok , Each line contains a set of queries , Among them i The row contains two integers li and ri, Indicates the second in the query sequence li Number to ri Sum of numbers .
【 Output format 】
output T that 's ok , Each line contains an integer representing the answer to the corresponding question .
【 sample input 】
3
1 1
1 3
5 8
【 sample output 】
1
4
8
【 Scale and agreement of evaluation cases 】

Only get 70% Points ......
import java.util.*; public class Main { public static void main(String[] args)
{ Scanner input = new Scanner(System.in); int xunwencishu=input.nextInt(); int
left[]=new int[xunwencishu]; int right[]=new int[xunwencishu]; int max=0;
// Indicates the maximum length of the query for the sequence , This value determines the approximate length of the sequence , Of course, this should or can not be considered .. for(int i=0;i<xunwencishu;i++) {
left[i]=input.nextInt(); if(left[i]>max) { max=left[i]; } right[i]=input.nextInt
(); if(right[i]>max) { max=right[i]; } } int xulie []=new int[max+1]; int index=
0; // According to the meaning of the topic , Initialization sequence . for(int i=1;index<=max;i++) { for(int j=1;j<=i;j++) { if(index
<=max) xulie[index++]=j; } } for(int i=0;i<xunwencishu;i++) { int sum=0; for(int
j=left[i]-1;j<=right[i]-1;j++) { sum+=xulie[j]; } System.out.println(sum); } }
}
test questions G: Sum and product

A solution :
Should not get full marks .... import java.util.*; public class Main { public static void main(
String[] args) { public static void main(String[] args) { Scanner input = new
Scanner(System.in); int n=input.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i
++) { a[i]=input.nextInt(); } int count=0; int ji=1; int sum=0; for(int i=0;i<n;
i++) { ji=1; sum=0; for(int j=i;j<n;j++) { ji*=a[j]; sum+=a[j]; if(sum==ji) {
count++; } } } System.out.println(count); } }
Waiting for change ....

Technology