当前位置:网站首页>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
边栏推荐
- JWT implements login authentication + token automatic renewal scheme, which is the correct posture!
- 基于gRPC编写golang简单C2远控
- Fujian vies for vc/pe
- 08.02 邻接表
- View drawing process 1-the relationship between view and window
- Nacos作为注册中心、配置中心入门使用篇-实现远程调用、动态获取配置文件、数据库配置信息
- [IO Development Notes] smart cloud intelligent watering device practice (3) - automatic code generation and transplantation
- 自己学习Cesium的笔记简介
- Liepin questionnaire star has become a "parasite" on wechat
- what is a kit in qt
猜你喜欢

2018 arXiv preprint | MolGAN: An implicit generative model for small molecular graphs

Write golang simple C2 remote control based on grpc

Development status of Dao

Height collapse caused by floating

Those environment configurations and plug-ins of idea

Makefile相关语法总结(Openc910)

光源控制器拨码开关使用说明

leetcode:857. 雇佣 K 名工人的最低成本【分块思考 + 由简单入手】

Relying on metauniverse and NFT, the world shows crazy "cutting leeks"?

Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
随机推荐
Blog Garden beautification skills summary
让程序在一秒或者多秒中做一件事情
Do you know why to design test cases after learning so long about use case design
Jd.com won the highest award for intelligent science and technology in China! Inventory JD system intelligent technology
ORM同时使用不同数据源和不同命名转换
7.27抢先看 | openEuler 志高远,开源汇智创未来-开放原子全球开源峰会欧拉分论坛最详细议程出炉
恋爱时各个顺序整理(历时两个月详细整理)
Introduction to the notes of learning cesium by yourself
Arduino实验一:双色灯实验
Overview of banking industry
Cached database for memcached
[tool] apifox
DAO 的发展状态
Redis 分布式锁 + Lua原子操作
Introduction to MySQL database
Financial institution map
DTS is equipped with a new self-developed kernel, which breaks through the key technology of the three center architecture of the two places Tencent cloud database
面试 必备
Promise me, don't write shit code after reading it..
Leetcode 122: the best time to buy and sell stocks II