当前位置:网站首页>Niuke - real exercise-01
Niuke - real exercise-01
2022-06-21 14:41:00 【Renshanren】
List of articles
Cattle guest - Real exercises -01
58 Same city 2020 Campus recruitment written test - Back end
The first question is


The first question is the code implementation
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String[] strList = str.split(",");
int count = 1;
for(int i = 1;i < strList.length;i++){
if(!strList[i].equals(strList[i-1])){
count++;
}
}
System.out.print(count);
}
}
The second question is



Question 2 code implementation
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int[][] list = new int[m][n];
for(int i = 0;i < m;i++){
for(int j = 0;j < n;j++){
list[i][j] = sc.nextInt();
}
}
int[][] dp = new int[m][n];
dp[0][0] = list[0][0];
for(int i = 1;i < n;i++){
dp[0][i] = dp[0][i-1] + list[0][i];
}
for(int i = 1;i < m;i++){
dp[i][0] = dp[i-1][0] + list[i][0];
}
for(int i = 1;i < m;i++){
for(int j = 1;j < n;j++){
dp[i][j] = Math.min(dp[i-1][j],dp[i][j-1]) + list[i][j];
}
}
//for(int i = 0;i < m;i++){
// for(int j = 0;j < n;j++){
// System.out.print(dp[i][j]);
// }
// System.out.println();
//}
System.out.print(dp[m-1][n-1]);
}
}
Third question



Third question code implementation
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int[] list = new int[m];
// Fill in the child's rating
for(int i = 0;i < m;i++){
list[i] = sc.nextInt();
}
// Make one tx Represents the smallest biscuit that each child should receive .
int[] childs = new int[m];
int minSum = 0;
childs[0] = 1;
// greedy , First determine the score of the left comparison , Then determine the score of the comparison on the right , The score on the left should be compared with that on the right .
for(int i = 1;i < m;i++){
if(list[i] > list[i-1]){
childs[i] = childs[i-1] + 1;
} else{
childs[i] = 1;
}
}
for(int i = m-2;i >= 0;i--){
if(list[i] > list[i+1]){
childs[i] = Math.max(childs[i],childs[i+1] + 1);
}
}
for(int i = 0;i < m;i++){
minSum += childs[i];
}
System.out.print(minSum);
}
}
summary
58 Yes. ACM Pattern , You need to import the library yourself , And you need to write your own input , I'm used to making force buckles, but I don't adapt to it . Then the question is very similar to the question practiced by Li Kou , I feel I have done everything , Good luck is also possible .
边栏推荐
- English accumulation__ annoyance
- Tcp/ip FAQs
- Mysql5.7 setup password and remote connection
- Numpy: basic package for high performance scientific computing & data analysis
- Analysis of ROC and AUC
- T32 custom menu bar
- SSH based command operation
- Reptile Foundation_ urllib
- Pyqt5 learning notes of orange_ Connect to SQL Server database
- Chapter 2 - physical layer (II) circuit switching, message switching and packet switching (datagram and virtual circuit)
猜你喜欢

Pyqt5 learning notes of orange_ Basic structure of pyqt5 GUI program
![Flex layout --- detailed explanation [Blue Bridge Cup classic dice layout]](/img/9b/bb030e7b4be833051d6bc3974e4184.jpg)
Flex layout --- detailed explanation [Blue Bridge Cup classic dice layout]
![[graduation project recommendation] - personnel management system](/img/b5/4235b54fa0da9e4637010a68bf848b.jpg)
[graduation project recommendation] - personnel management system

Summary of web development technology knowledge

HSV color model and color component range in opencv

Qt-5-multi window programming
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures!

Mr. Ali taught you how to use JMeter for pressure test (detailed drawing)

Mqtt keepalive and reconnect

Chapter 6 - application layer
随机推荐
Qt-4-common classes and components
[graduation project recommendation] - personnel management system
Because the college entrance examination is the most fair competition and selection
What are the log files in MySQL?
Chapter 6 - application layer
Configuring MySQL master-slave and implementing semi synchronous replication in docker environment
Three versions realize black-and-white theme switching
Tcp/ip FAQs
Read distributed consistency protocols 2pc and 3pc
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures!
JS written test question: this
Oracle client11 and pl/sql12 installation
How is the redemption time of financial products stipulated?
ARP interaction process
Summary of common libraries in machine learning
Analysis of ROC and AUC
Installation of oracle19c under alicloud lightweight application server linux-centos7
Explain the high availability features of Nacos
What fun things can a desk service do
Redis learning (3) -- persistence mechanism