当前位置:网站首页>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 .
边栏推荐
- Win10 installation and configuration mongodb
- So many statistical charts? This visualizer is great~~
- Chapter 6 - application layer
- Installation of MySQL 8.0.19 under alicloud lightweight application server linux-centos7
- Promotion guide for large enterprises: material preparation, PPT writing and on-site defense
- Reverse generate the corresponding DTD constraint according to the XML file
- Record the processing process of slow response of primary system
- Computer shortcuts During sorting, fill in as needed
- Promotion guide for large enterprises: material preparation, PPT writing and on-site defense
- Use of MySQL 8.0.19 under alicloud lightweight application server linux-centos7
猜你喜欢

Qt-6-file IO

Record the processing process of slow response of primary system

CSDN's test teacher teaches JMeter to generate stress test reports

Configuration of oracle19c under alicloud lightweight application server linux-centos7

MySQL failover and master-slave switchover based on MHA

The code remotely calls aria2 to download URL resources or BT seeds

How is the network connected

2021 the latest selenium truly bypasses webdriver detection

Use Matplotlib to draw the first figure

Chapter 5 - application layer
随机推荐
The whole process of Netease cloud music API installation and deployment [details of local running projects and remote deployment]
Pyqt5 learning notes of orange_ Connect to SQL Server database
Because the college entrance examination is the most fair competition and selection
Write a code hot deployment
How does JMeter implement interface association?
Vscade, open a folder or workspace... (file - > open folder) solution
ARP interaction process
Judge password strength - Optimization
Design interface automation test cases by hand: establish database instances and test case tables
A complete set of skills that a software test engineer needs to master
HSV color model and color component range in opencv
Configuration of oracle19c under alicloud lightweight application server linux-centos7
LINQ extension methods - any() vs. where() vs. exists() - LINQ extension methods - any() vs. where() vs. exists()
Make word2vec for Bert model
English accumulation__ annoyance
Making my footprint map using API
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures!
Invisible characters encountered \u200b
Machine learning model training template
Summary of web development technology knowledge