当前位置:网站首页>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
边栏推荐
- 毕业5年,从信息管理转行软件测试工程师,我的月薪终于突破了12k
- [RequireComponent(typeof(....))]
- Add resource files for the project and pictures for buttons in QT
- Sort out each order when you are in love (it takes two months to sort out in detail)
- [basics of C language] 17 preliminary study of linked list
- 光源控制器拨码开关使用说明
- 09.01 depth first search
- 面试 必备
- 缓存数据库Memcached
- leetcode:857. 雇佣 K 名工人的最低成本【分块思考 + 由简单入手】
猜你喜欢

MySQL recommendation

Embedded sig | distributed soft bus

Spend 120 billion to build a "subway" to connect 4 trillion cities. What is Guangdong thinking?

Concept and classification of processes

LeetCode 121:买卖股票的最佳时机

7.27抢先看 | openEuler 志高远,开源汇智创未来-开放原子全球开源峰会欧拉分论坛最详细议程出炉

SQL injection less26 (filter spaces and comments, and use error injection without spaces)

缓存数据库Memcached

Arduino实验一:双色灯实验

DAO 的发展状态
随机推荐
什么是 Base64 ?
Chapter 15 MySQL user management
Development status of Dao
【论文阅读】LOGAN:Membership Inference Attacks Against Generative Models
【地平线旭日X3派试用体验】+开箱帖
【Qt多线程之线程的等待和唤醒】
Regular expressions and bypass cases
Excel VBA quick start (XII. Common usage of like comparison)
Blog Garden beautification skills summary
jmeter -- response中文乱码处理
Proto basic grammar of protobuf
The PRI that Hillhouse joined, including Junlian, Huakong, Shengshi, Lvdong and other 100 institutions, was killed
2018 arXiv preprint | MolGAN: An implicit generative model for small molecular graphs
Redis distributed lock + Lua atomic operation
【Io开发笔记】机智云智能浇花器实战(1)-基础Demo实现
Iptables prevents nmap scanning and enables incremental backup of binlog
Weilai cup 2022 Niuke summer multi school training camp 1
DTS搭载全新自研内核,突破两地三中心架构的关键技术|腾讯云数据库
Nacos作为注册中心、配置中心入门使用篇-实现远程调用、动态获取配置文件、数据库配置信息
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