## One 、 graphic display

This question is simple , But what we need to pay attention to is , Every “*” There's a space behind it 】

* * * * *

* * * *

* * *

* *

*

import java.util.Scanner; public class Main {

public static void main(String[] args) {

Scanner mScanner = new Scanner(System.in);

int n = mScanner.nextInt();

for (int i = n; i > 0; i--) {

if (i != n) {

System.out.println();

}

for (int j = 0; j < i; j++) {

System.out.print("* ");

}

}

}

}

Two 、 Sort

Input format ： There is only one line of input , Three integers , Space separates the middle .

Output format ： There is only one line of output , That is, the result after sorting .

I/o sample

import java.util.Arrays;

import java.util.Scanner; public class Main{ public static void main(String[] args) {

Scanner mScanner = new Scanner(System.in);

int[] array = new int[3];

for (int i = 0; i < array.length; i++) {

array[i] = mScanner.nextInt();

}

Arrays.sort(array);

for (int i = array.length - 1; i >= 0; i--) {

System.out.print(array[i] + " ");

}

} }

## 3、 ... and 、2 To the power of

Put this 2 The decimal representation is written as 2 The sum of the powers of , Let's put the power up front , We can get the following expression ：137=2^7+2^3+2^0

Now the power of the Convention is expressed in parentheses , namely a^b Expressed as a（b）

here ,137 Can be expressed as ：2（7）+2（3）+2（0）

further ：7=2^2+2+2^0 （2^1 use 2 Express ）

3=2+2^0

So finally 137 Can be expressed as ：2（2（2）+2+2（0））+2（2+2（0））+2（0）

And so on ：1315=2^10+2^8+2^5+2+1

therefore 1315 Finally, it can be expressed as ：

2（2（2+2（0））+2）+2（2（2+2（0）））+2（2（2）+2（0））+2+2（0）

Tips

It's easier to implement recursively , You can output... Recursively

import java.util.Scanner; public class Main{

public void fun(double e) {

double d = e;

if (d == 1) {

System.out.print("2(0)");

} else {

if (d == 2) {

System.out.print("2");

} else {

int x = 1;

int m = 0;

while (m == 0) {

if ((Math.pow(2, x + 1) > d) && (d >= Math.pow(2, x))) {

m = 1;

if (d == Math.pow(2, x)) {

System.out.print("2");

if (x == 1) {

} else {

System.out.print("(");

fun(x);

System.out.print(")");

}

} else {

System.out.print("2");

if (x == 1) {

} else {

System.out.print("(");

fun(x);

System.out.print(")");

}

System.out.print("+");

fun(d - Math.pow(2, x));

}

} else {

x++;

}

}

}

}

} public static void main(String[] args) {

Scanner mScanner = new Scanner(System.in);

double n = mScanner.nextInt();

Main cm = new Main();

cm.fun(n);

}

}

## Four 、 Prefix expression

Input format ： There is only one line of input , That is, a prefix expression string .

Output format ： Output the corresponding calculation results （ If it's division , Direct adoption c Linguistic “/” Operator , The result is an integer ）.

I/o sample

import java.util.Scanner; public class Main { public static void main(String[] args) {

Scanner mScanner = new Scanner(System.in);

String mm = mScanner.next();

int a = mScanner.nextInt();

int b = mScanner.nextInt();

if (mm.equals("+")) {

System.out.println(a+b);

}else if (mm.equals("-")) {

System.out.println(a-b);

}else if (mm.equals("*")) {

System.out.println(a*b);

}else if (mm.equals("/")) {

System.out.println(a/b);

}

}

}

## 5、 ... and 、Anagrams problem

Input format ： There are two lines of input , It's two words .

Output format ： The output has only one letter Y or N, respectively Yes and No.

I/o sample

Nuclear

import java.util.Arrays;

import java.util.Scanner; public class Main{ public static void main(String[] args) {

Scanner mScanner = new Scanner(System.in);

String str1 = mScanner.next().toLowerCase();

String str2 = mScanner.next().toLowerCase();

if (str1.length() == str2.length()) {

char[] arr1 = fun(str1);

char[] arr2 = fun(str2);

boolean tag = true;

for (int i = 0; i < arr1.length; i++) {

if (arr1[i] != arr2[i]) {

tag = false;

}

}

if (tag) {

System.out.println("Y");

}else{

System.out.println("N");

}

} else {

System.out.println("N");

}

} public static char[] fun(String str) {

char[] array = str.toCharArray();

Arrays.sort(array);

return array;

} }

## 6、 ... and 、 The most frequent integer

Write a program , Read in a set of integers , This group of integers is arranged from small to large , The number of them N It's also entered by the user , Not more than 20. Then the program will count this array , Print out the value of the most frequent array element . If two element values appear the same number of times , That is to tie for the first place , Then print only the smaller value .

Input format ： The first line is an integer N,N £ 20; Next there is N That's ok , Each line represents an integer , And in order from small to large .

Output format ： There is only one line of output , That is, the element value with the most occurrences .

I/o sample

100

150

150

200

250

import java.util.Scanner; public class Main{ public static void main(String[] args) {

Scanner mScanner = new Scanner(System.in);

int m = mScanner.nextInt();

if (m < 1 || m > 20) {

return;

}

int[] array = new int[m];

for (int i = 0; i < m; i++) {

array[i] = mScanner.nextInt();

} int max = 0;

int tag = 0;

int num = 0;

for (int i = 1; i < array.length; i++) {

if (array[i - 1] == array[i]) {

tag++;

} else {

tag = 0;

}

if (tag > max) {

num = array[i];

max = tag;

}

}

if (num==0) {

num = array[0];

}

System.out.println(num);

} }

## 7、 ... and 、 String statistics

The second line is the string S.

L Greater than 0, And no more than S The length of .

sample input 1：

4

bbaabbaaaaa

sample output 1：

bbaa

sample input 2：

2

bbaabbaaaaa

sample output 2：

aa

S All characters in are lowercase letters .

Tips

Enumerate all possible substrings , Count the number of times , Find the one who meets the criteria

## 8、 ... and 、 Matrix multiplication

Next m That's ok , Each row s An integer separated by spaces , According to matrix A（i,j）.

Next s That's ok , Each row n An integer separated by spaces , According to matrix B（i,j）.

1 0 -1

1 1 -3

0 3

1 2

3 1

-8 2

Tips

matrix C Should be m That's ok n Column , among C(i,j) Equal matrix A The first i Row vectors and matrices B The first j The inner product of a column vector .

For example, in the example C(1,1)=(1,0,-1)*(0,1,3) = 1 * 0 +0*1+(-1)*3=-3

import java.util.Scanner; public class Main { public static void main(String[] args) {

Scanner mScanner = new Scanner(System.in);

int m = mScanner.nextInt();

int s = mScanner.nextInt();

int n = mScanner.nextInt();

int[][] a = new int[m][s];

int[][] b = new int[s][n];

int[][] c = new int[m][n];

for (int i = 0; i < m; i++) {

for (int j = 0; j < s; j++) {

a[i][j] = mScanner.nextInt();

}

}

for (int i = 0; i < s; i++) {

for (int j = 0; j < n; j++) {

b[i][j] = mScanner.nextInt();

}

} getMatrix(a, b); } public static void getMatrix(int[][] a, int[][] b) {

int[][] c = new int[a.length][b[0].length];

for (int i = 0; i < a.length; i++) {

for (int j = 0; j < b[0].length; j++) {

int sum = 0;

for (int k = 0; k < b.length; k++) {

sum += a[i][k] * b[k][j];

}

c[i][j] = sum;

}

} for (int i = 0; i < a.length; i++) {

for (int j = 0; j < b[0].length; j++) {

System.out.print(c[i][j] + "\t");

}

System.out.println();

} } }

## Nine 、 toggle case

Input format ： Enter a string , And this string contains only English letters , Does not contain other types of characters , There are no spaces .

Output format ： Output converted String .

I/o sample

import java.util.Scanner;

public class Main { public static void main(String[] args) {

Scanner mScanner = new Scanner(System.in);

String str = mScanner.next();

char[] arr = str.toCharArray();

for (int i = 0; i < arr.length; i++) {

if (Character.isLowerCase(arr[i])) {

str = String.valueOf(arr[i]).toUpperCase();

} else {

str = String.valueOf(arr[i]).toLowerCase();

}

System.out.print(str);

}

} }

## Ten 、 Dynamic arrays use

3 4 0 0 2

3 2 7 5 2 9 1

import java.util.ArrayList;

import java.util.Scanner; public class Main { public static void main(String[] args) {

Scanner mScanner = new Scanner(System.in);

int length = mScanner.nextInt(); int sum = 0;

int average = 0;

for (int i = 0; i < length; i++) {

sum = sum + mScanner.nextInt();

}

System.out.println(sum + " " + sum / length); } }

## 11、 ... and 、 Delete array zeros

5

3 4 0 0 2

Sample output :（ Output format description ：3 Is the number of nonzero data ,3 4 2 It's separated by spaces 3 It's a nonzero integer ）

3

3 4 2

0 0 7 0 0 9 0

7 9

0 0 0

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner mScanner = new Scanner(System.in);

int count = mScanner.nextInt(); List<Integer> list = new ArrayList<Integer>(); // int[] arr = new int[count];

for (int i = 0; i < count; i++) {

// arr[i] = mScanner.nextInt();

list.add(mScanner.nextInt());

}

int length = CompactIntegers(list, count);

System.out.println(length); for (int i = 0; i < list.size(); i++) {

System.out.print(list.get(i) + " ");

} } public static int CompactIntegers(List<Integer> list, int count) {

int ss = count;

for (int i = 0; i < list.size(); i++) {

if (list.get(i) == 0) {

list.remove(i);

ss--;

i--;

}

}

return ss;

}

}

** notes ： This article is original , First in blog Park , Reprint please indicate the source .[http://www.cnblogs.com/zhjsll/p/4412250.html]**

## Blue Bridge Cup algorithm training < One > More articles about

- Java Realization Blue Bridge Cup Algorithm training Monkeys eat steamed buns （ violence ）
test questions Algorithm training Monkeys eat steamed buns Problem description Once upon a time , There is a monkey who is very good at eating steamed buns , It can eat countless steamed buns , however , It eats different buns at different speeds : Meat buns are eaten every second x individual : Leek bag every second y individual : Steamed buns without stuffing are eaten every second z individual : Now there is x1 A meat ...

- Java Realize the Blue Bridge Cup Algorithm training Equal to n The least complete square of
test questions Algorithm training Equal to n The least complete square of Resource constraints The time limit :1.0s Memory limit :256.0MB Problem description The output is equal to n The smallest complete square of . If a number can be expressed as the square of a natural number , This number is called completely flat ...

- Blue Bridge Cup algorithm training java Algorithm Expression evaluation
Problem description Enter a legal expression that contains only addition, subtraction, division and parentheses , Find the value of the expression . Where division means integral division . Input format The input line , Contains an expression . Output format Output the value of this expression . The sample input 1-2+3*(4-5) Sample output - ...

- java Realization Blue Bridge Cup Algorithm training Password Suspects
Problem description When I was young , The hero of our story -- King Copa-- His personal data is not completely secure . For him it was , It's unacceptable . therefore , He invented a code , It's easy to remember and hard to crack . later , He just knew that this kind of password is an odd number in length ...

- Blue Bridge Cup Algorithm training Torry Perplexity of ( Basic type )（ Water problem , Sieve to find prime number ）
Algorithm training Torry Perplexity of ( Basic type ) The time limit :1.0s Memory limit :512.0MB Problem description Torry I love math since I was a child . One day , The teacher told him , image 2.3.5.7…… Such numbers are called prime numbers .Torry A sudden ...

- Blue Bridge Cup Algorithm training Section k Large number query （ Water problem ）
Algorithm training Section k Large number query The time limit :1.0s Memory limit :256.0MB Problem description Given a sequence , The second in the sequence of each inquiry l The number to the first r The number of K Which is the big number . Input format The first line contains a number n, Represents sequence length . ...

- Blue Bridge Cup -- Algorithm training Section k Large number query
Algorithm training Section k Large number query The time limit :1.0 ...

- Blue Bridge Cup Algorithm training ALGO-116 The biggest formula
Algorithm training The biggest formula The time limit :1.0s Memory limit :256.0MB Problem description The subject is very simple , give N A digital , Don't change their relative position , Add... In the middle K A multiplication sign and N-K-1 Plus sign ,( Put in parentheses ) Make the final result as much as possible ...

- Blue Bridge Cup algorithm training Section k Large number query
Algorithm training Section k Large number query Problem description Given a sequence , The second in the sequence of each inquiry l The number to the first r The number of K Which is the big number . Input format The first line contains a number n, Represents sequence length . The second line contains n A positive integer , Represents a given sequence . Third ...

- Blue Bridge Cup Algorithm training ALGO-15 Traveler's budget
Algorithm training Traveler's budget The time limit :1.0s Memory limit :256.0MB Problem description A traveler wants to drive a car from one city to another at the least cost ( Suppose the fuel tank is empty when you start ). Given the distance between two cities D1. automobile ...

## Random recommendation

- fasicon.js （ No QR code version , If needed js To create a QR code version, please contact me ：770959294@qq.com）
/*** Created by Zhangyunshan on 2016/12/9.*/(function(wins,doct){wins.fasicon = function(){this.name = " ...

- [Data Structure] Bit-map Space compression and quick sort to remove duplication
Bit-map It's a very clever data storage structure . So-called Bit-map Just use one bit Bit to mark the corresponding Value, and Key That's the element . Because of the adoption of Bit Store data in units , Can greatly save storage space .Bit-ma ...

- How to use it Github+Appveyor+Nuget Build your own .net core Open source library
The following tutorial is based on the fact that you have a hosting in Github Upper .net core project , If you don't have it, you can do it yourself fork You can create a default project by yourself . We need to generate nuget In the package project project.json file , of ...

- android Battery management system from the top java Calls to the underlying driver （ Reprint ）
1. summary With the rapid development of mobile intelligent devices , The battery's endurance ability has induced the purchase choice of the mass consumers in a large extent ,android Whether the power management of the system is reasonable or not directly affects the battery's endurance , And the battery system is part of it , It's mainly used for battery like ...

- mysql High performance
Chapter 1 : Shared lock ( Read the lock ), Exclusive lock ( Write lock ) The storage engine used to query data tables :show table status like ' Table name ' \G Storage engine for converting data tables :alter table Table name engine= lead ...

- java cannot find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
appear java cannot find the tag library descriptor for "http://java.sun.com/jsp/jstl/core" The main wish is ...

- MYSQL5.6 database ZIP Installation and VS Note for use in the project
Hang up resources first , Download address : http://download.softagency.net/MySQL/Downloads/. find MYSQL5.6, The two versions depend on the system. What I ordered is 64 Bit :http://down ...

- stay MVC Add exception to add log
MVC It's a great structure , Basically, you can find a place where you can think of it , for example IActionFilter,IResultFilter,IAuthorizationFilter as well as IExceptionFilter following ...

- Entity Framework Code First Appointment
Code First So that you can pass C# perhaps Visual Basic .NET To describe the model , The basic rules of the model are checked by using conventions , And conventions are a set of built-in rules . stay Code First Class based definitions in are defined through a ...

- FTP Users can't log in to debug details
FTP As a simple and convenient file sharing technology , It is used in many enterprises . If enabled FTP Verification control of , Administrators can set different access rights for different users , Control user access to specific content .IIS Medium FTP There is only one way to verify a site , That is, the basic test ...