This article will explain some of the problems ( Because some questions don't work !! It's too delicious ), If you find that there is a problem with the answer , You can leave a message , Let's discuss it together .

test questions A: 

answer :624
public static void main(String[] args) { // TODO Auto-generated method stub
int a = 1; int count = 0; while (true) { String b = a + ""; for (int i = 0; i <
b.length(); i++) { if (b.charAt(i) == '2') { count++; } } a++; if (a == 2021) {
System.out.println(count); return; } } }
The first question is relatively simple , Directly from 1 reach 2020 ergodic , Judge how many 2 that will do .

test questions B:

answer :16520
public static void main(String[] args) { int l = 1000; String arr[] = new
String[300]; int arr2[][] = new int[300][300]; Scanner s = new
Scanner(System.in); int count = 0; // How many 2020 String target = "2020"; String
b = ""; for (int i = 0; i < 300; i++) { arr[i] = s.next(); } // Converts the input string to an array
for (int i = 0; i < arr.length; i++) { for (int z = 0; z < arr[i].length();
z++) { arr2[i][z] = (arr[i].charAt(z) - '0'); } } // The method of judging the diagonal angle of up, down, left and right for (int i =
0; i < arr2.length; i++) { for (int j = 0; j < arr2[i].length; j++) { if
(arr2[i][j] == 2) { b = ""; // Left -》 right // if (j + 4 <= arr2[i].length) { // for
(int k = j; k < j + 4; k++) { // b = b + arr2[i][k]; // } // if
(b.equals(target)) { // count++; // b = ""; // } // } // upper -》 lower // if (i + 4 <=
arr2[i].length) { // for (int k = i; k < i + 4; k++) { // b = b + arr2[k][j];
// } // if (b.equals(target)) { // count++; // b = ""; // } // } Top left - > lower right if
(i + 4 <= arr2[i].length && j + 4 <= arr2[i].length) { int n = i; int m = j;
for (int k = 0; k < 4; k++) { b = b + arr2[n][m]; n++; m++; } if
(b.equals(target)) { count++; b = ""; } } } } } System.out.println(count); }

Thinking of solving problems : first , There are three ways to find it , Each character must be taken out to judge and splice , To check whether the conditions are met . But if you want to take out every character , The best way to do this is to change the value you entered , Store each character in a two-dimensional array . This will facilitate the subsequent calculation . first ,
You need to know that the input value needs to be stored in a one-dimensional string array , Each line is stored in the array as a string , Then the one-dimensional string array is converted into a two-dimensional array . Save each character in the array to the array . Then we start traversing the two-dimensional array , If the current character is 2, You need to judge the character from left to right , From top to bottom , Does it meet the requirements from top left to bottom right , If the requirements are met, then count++, What we need to pay attention to here is to prevent the array from crossing the bounds .

I have a problem here , I use three if To judge the left -> right , upper -> lower , Top left ->
lower right , But if I do three at the same time if In my words , The results are not accurate . If only one is executed at a time if sentence , The result is accurate , Now there's no reason . So I ran the program three times , The left and right angles are calculated respectively -> Right common 5505 One that meets the condition , From above -> There are 5509 One that meets the condition , From the top left -> lower right , share 5506 One that meets the condition . So the result is 5505+5506+5509
= 16520. If you find out why the three if At the same time, the reasons for different implementation results are analyzed , You can exchange messages !!! 

 

test questions C:

answer : 761
public static void main(String[] args) { // TODO Auto-generated method stub
int a = 1; for (int i = 0; i < 20; i++) { a = a + (i * 4);
System.out.println(a); } }

Thinking of solving problems : You can find it by handwriting a few lines first , The value of the first row and first column is 1, The value of the second row and second column is 5. The value of the third row and column is 13, The value of the fourth row and column is 25, If you look closely, you can see that the second i Line number i The value of the column is  
a = a + (i*4).

test questions F:

answer : jonmlkihgfedcba
public static void main(String[] args) { // TODO Auto-generated method stub
String a = "jonmlkihgfedcba"; StringBuffer sb = new StringBuffer(a); int i = 0;
int count = 0; while (true) { if (i < a.length() - 1 && a.charAt(i) >
a.charAt((i + 1))) { sb.replace(i, i + 1, a.charAt((i + 1)) + ""); sb.replace(i
+ 1, i + 2, a.charAt((i)) + ""); a = sb.toString(); count++; continue; } else
if (i < a.length() - 1 && i - 1 >= 0 && a.charAt(i) < a.charAt((i - 1))) {
sb.replace(i - 1, i, a.charAt((i)) + ""); sb.replace(i, i + 1, a.charAt((i -
1)) + ""); a = sb.toString(); count++; i--; continue; } else { i++; if (i ==
a.length() - 1) { System.out.println(count); System.out.println(a); break; } }
} if (count == 100) { System.out.println(a); return; } }

Thinking of solving problems : First, according to the exchange rules given in the title , Write a complete program , And when the exchange is complete , To output the number of exchanges (count), And the final result (a), Output these two values to determine whether the program is correct . for example : When a by lan Time , output 1
and aln; When a by waqs Time , output 3 and aqsw. here , You can start looking for the shortest length , And the smallest dictionary order string . There is a mistake in the last sentence of the title , It should be a string with no duplicate characters . When a=zyxw Time , Output count The value is 6, At this point you should know , When the length of the string is 4 Time , The maximum number of exchanges is 6. Because the leftmost one has to move to the rightmost one , The one on the far right should be moved to the far left . So first, find out the string length that meets the condition according to this , When a=zyxwvutsrqponm Time , The maximum number of exchanges is 91, When a
= zyxwvutsrqponml Time , The maximum number of exchanges is 105, So the number of exchanges is 100 The length of the string must be 15. It also needs the minimum dictionary order , So from a Start flashback 15 Characters ,
a=onmlkjihgfedcba Time , The number of exchanges is 105 second , In order to meet the exchange times 100 second , take j Move forward 5 It's just a bit . So the answer is jonmlkihgfedcba.

 

test questions F:
public static void main(String[] args) { Scanner s = new Scanner(System.in);
int count = s.nextInt(); DecimalFormat df = new DecimalFormat(".00"); int arr[]
= new int[count]; double num = 0; for (int i = 0; i < arr.length; i++) { arr[i]
= s.nextInt(); num += arr[i]; } Arrays.sort(arr); System.out.println(arr[count
- 1]); System.out.println(arr[0]); System.out.println(df.format(num / count)); }
There is no technical content in this problem , The main purpose of the examination is the foundation , Interested friends can keep a variety of decimal test .

test questions G:
public static void main(String[] args) { // TODO Auto-generated method stub
Scanner s = new Scanner(System.in); int max = -1; char maxs = 'a'; String a =
s.next(); HashMap<String, Integer> map = new HashMap<>(); for (int i = 0; i <
a.length() - 1; i++) { if (map.get(a.charAt(i) + "") != null) { int num = (int)
map.get(a.charAt(i) + ""); map.remove(a.charAt(i) + ""); num++;
map.put(a.charAt(i) + "", num); } else { map.put(a.charAt(i) + "", 1); } }
Object[] arr = map.entrySet().toArray(); for (int i = 0; i < arr.length; i++) {
String arr2[] = (arr[i] + "").split("="); if ((Integer.parseInt(arr2[1])) >=
max) { if ((Integer.parseInt(arr2[1])) == max) { if (arr2[0].charAt(0) > maxs)
{ maxs = arr2[0].charAt(0); continue; } } max = (Integer.parseInt(arr2[1]));
maxs = arr2[0].charAt(0); } } System.out.println(maxs);
System.out.println(max); }
Thinking of solving problems : use map Set to save the number of times each character appears , Finally, the result is transformed into an array for traversal , Find the most frequent characters .

test questions I:
public static void main(String[] args) { // TODO Auto-generated method stub
Scanner s = new Scanner(System.in); String a = s.next(); HashMap<String,
Integer> map = new HashMap<>(); int count = 0; for (int i = 0; i < a.length();
i++) { for (int j = i + 1; j <= a.length(); j++) { String b = a.substring(i,
j); map.clear(); for (int k = 0; k < b.length(); k++) { if (map.get(b.charAt(k)
+ "") == null) { map.put(b.charAt(k) + "", 1); } } count += map.size(); } }
System.out.println(count); }

Thinking of solving problems : First, the double finger is used to intercept the string , After interception, each string of the string is taken out one by one and stored in the map aggregate , If map The string is not put into this collection map In the collection , Finally get size. Actually, we can use it here set The characteristics of self weight removal , To replace map aggregate .

 

That's what I wrote , Some of the questions haven't been answered completely , This article will be revised continuously in the future , Continue to complete the solution . If there is anything wrong with the above answers or can be optimized , Welcome to correct !

Technology
©2019-2020 Toolsou All rights reserved,
tkinter Implementation of user login interface Vue Invalid render dynamic component in subcomponent ( First invalid , Valid for the second time )9 ride 9 Sudoku C/C++ Memory model TypeScript actual combat -12-TS The mechanism of type checking - Type inference Java Thread safety and insecurity JLink,STLink,DAPLink,CMSIS DAP Differences in use Chapter 10 use SpringMVC Frame transformation of supermarket order management system -1C Language calculation of deposit interest About the Blue Bridge Cup , Things you should know !