当前位置:网站首页>Parameter analysis and stone jumping board
Parameter analysis and stone jumping board
2022-07-26 22:33:00 【InfoQ】
️ Argument parsing ️
Topic details
- Parameters 1: Command word xcopy
- Parameters 2: character string /s
- Parameters 3: character string c:\
- Parameters 4: character string d:\e
xcopy /s c:\\ d:\\e
4
xcopy
/s
c:\\
d:\\e
Their thinking

""""" The number of spaces outside quotation marks +1""""""""""- situation 1: The traversal characters are
"as well as""In the character , encounter", There has been no line feed output " After all characters until encountered again"
- situation 2: The traversal characters are
"Space outside , Output carriage return
- situation 3: The traversal character is neither a space nor
", Output all characters before spaces directly without line breaks
Source code
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
// The first part , Calculate the number of parameter strings , That is to calculate the number of effective spaces
char[] cs = str.toCharArray();
int ans = 0;
int n = cs.length;
for (int i = 0; i < n; i++) {
// situation 1: with " String ,"" The string inside is a whole , It's a parameter , Including spaces
if (cs[i] == '"') {
// Skip calculation " The space inside
i++;
while (i < n && cs[i] != '"') {
i++;
}
} else if (cs[i] == ' ') {
ans++;
}
}
// The final number of parameters is the number of valid split spaces +1
ans++;
System.out.println(ans);
// The second part , Output specific parameters
int i = 0;
while (i < n) {
// situation 1: The traversal characters are " as well as "" In the character , encounter ", There has been no line feed output " After all characters until encountered again "
// situation 2: The traversal characters are " Space outside , Output carriage return
// situation 3: The traversal character is neither a space nor ", Directly output all characters before spaces
if (cs[i] == '"') {
// Output directly without line breaks "" All the characters in it
i++;
while (i < n && cs[i] != '"') {
System.out.print(cs[i++]);
}
i++;
} else if (cs[i] == ' ') {
// encounter " Output carriage return in outer space
System.out.println();
i++;
} else {
// encounter " The outside is not " And non spaces , Direct output without line breaks
while (i < n && cs[i] != ' ') {
System.out.print(cs[i++]);
}
}
}
}
}
summary
️ Jumping stone slab ️
Topic details
4 24
5
Their thinking

kk1kSource code
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
// exclude n==m The situation of
if (n == m) {
System.out.println(0);
return;
}
// State definition : Definition f[i] To jump to the i The minimum number of steps for a stone slab .
// Determine the initial state :f[n] = 0
// State transition equation : You might as well start from j A stone slab jumps to the i A slate ,j A divisor of is a, be i=j+a,
// because j And a The value of is not unique , We take the minimum number of steps in all cases , namely f[i]=f[j+a]=min(f[j])+1
// If the value is f[i]=0, Expressed as the starting point , We use -1 It means that it will not pass through i A slate
int[] f = new int[m+1];
Arrays.fill(f,-1);
f[n] = 0;
for (int j = n; j <= m; j++) {
//f[j] = 0 The starting point f[j]=-1 It means that it will not pass through j A slate
if (f[j] == -1) {
continue;
}
List<Integer> list = find(j);
for (int a : list) {
if (j + a <= m) {
if (f[j + a] == -1) {
f[j + a] = f[j] + 1;
} else {
f[j + a] = (f[j] + 1) < f[j + a] ? (f[j] + 1) : f[j + a];
}
}
}
}
int ans = f[m];
System.out.println(ans);
}
// Find a divisor
private static List<Integer> find(int n) {
List<Integer> list = new ArrayList<>();
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
list.add(i);
if (n / i != i) {
list.add(n / i);
}
}
}
return list;
}
}
summary
边栏推荐
- 09.01 depth first search
- Determine the dimension of numpy array array
- 挖财钱堂和启牛学堂哪个更好一些?是安全的吗
- Excel-vba quick start (XI. Common string operations)
- JSON字符串转化为JSON对象,获取某个key的值,判断某个key是否存在
- Mate30系列发布:华为的重构影像之路还能走多远?
- Add resource files for the project and pictures for buttons in QT
- leetcode:857. 雇佣 K 名工人的最低成本【分块思考 + 由简单入手】
- Does Guosen Securities charge for opening a mobile account? Is it safe to open an account?
- The PRI that Hillhouse joined, including Junlian, Huakong, Shengshi, Lvdong and other 100 institutions, was killed
猜你喜欢
随机推荐
Write golang simple C2 remote control based on grpc
Matlab solution of the densest stacking and smallest circumscribed square of N circles (two-dimensional, three-dimensional, etc. circle packing problem)
光源控制器拨码开关使用说明
: could not determine a constructor for the tag ! RootAdmin
Cached database for memcached
JMeter -- response Chinese garbled code processing
【Io开发笔记】机智云智能浇花器实战(3)-自动生成代码移植
Promise me, don't write shit code after reading it..
Sort out each order when you are in love (it takes two months to sort out in detail)
[RequireComponent(typeof(....))]
2022年最新西藏建筑安全员模拟题库及答案
Summary of debugging stc8a8k64d4 MCU 485 communication
[try to hack] firewall (I)
Is it safe to open an account for flush mobile stock trading? How to open an account
[IO Development Notes] smart cloud intelligent watering device practice (3) - automatic code generation and transplantation
what is a kit in qt
08.02 adjacency table
NVIDIA SMI error: NVIDIA SMI has failed because it could't communicate with the NVIDIA driver complete record
Proto basic grammar of protobuf
View drawing process 1-the relationship between view and window






![[waiting and wakeup of QT multithreaded threads]](/img/9b/fe16926dc126e93f155b0162cc329d.png)

