当前位置:网站首页>参数解析与跳石板
参数解析与跳石板
2022-07-26 21:38:00 【InfoQ】
️参数解析️
题目详情
- 参数1:命令字xcopy
- 参数2:字符串/s
- 参数3:字符串c:\
- 参数4: 字符串d:\e
xcopy /s c:\\ d:\\e
4
xcopy
/s
c:\\
d:\\e
解题思路

"""""引号外空格数量+1""""""""""- 情况1:遍历的字符为
"以及""内的字符, 遇到",一直无换行输出"后所有字符直到再次遇到"
- 情况2:遍历的字符为
"外的空格,输出回车
- 情况3:遍历的字符既不是空格也不是
",直接不换行输出空格前所有字符
源代码
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
//第一部分,计算参数字符串的个数,也就是计算有效空格的数量
char[] cs = str.toCharArray();
int ans = 0;
int n = cs.length;
for (int i = 0; i < n; i++) {
//情况1:带有"的字符串,""里面的字符串为一整体,是一个参数,包括空格也算
if (cs[i] == '"') {
//跳过计算"里面的空格
i++;
while (i < n && cs[i] != '"') {
i++;
}
} else if (cs[i] == ' ') {
ans++;
}
}
//最终参数个数为有效分割空格数+1
ans++;
System.out.println(ans);
//第二部分,输出具体参数
int i = 0;
while (i < n) {
//情况1:遍历的字符为"以及""内的字符, 遇到",一直无换行输出"后所有字符直到再次遇到"
//情况2:遍历的字符为"外的空格,输出回车
//情况3:遍历的字符既不是空格也不是",直接输出空格前所有字符
if (cs[i] == '"') {
//直接不换行输出""里面所有字符
i++;
while (i < n && cs[i] != '"') {
System.out.print(cs[i++]);
}
i++;
} else if (cs[i] == ' ') {
//遇到"外空格输出回车
System.out.println();
i++;
} else {
//遇到"外的非"与非空格,直接无换行输出
while (i < n && cs[i] != ' ') {
System.out.print(cs[i++]);
}
}
}
}
}
总结
️跳石板️
题目详情
4 24
5
解题思路

kk1k源代码
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();
//排除n==m的情况
if (n == m) {
System.out.println(0);
return;
}
//状态定义:定义f[i]为跳到第i块石板时的最小步数。
//确定初始状态:f[n] = 0
//状态转移方程:不妨设从第j块石板跳到第i块石板,j的一个约数为a,则i=j+a,
//由于j与a的值不唯一,我们取所有情况的最小步数,即f[i]=f[j+a]=min(f[j])+1
//如果值为f[i]=0,表示为起点,我们使用-1表示不会经过第i块石板
int[] f = new int[m+1];
Arrays.fill(f,-1);
f[n] = 0;
for (int j = n; j <= m; j++) {
//f[j] = 0 表示起点 f[j]=-1表示不会经过第j块石板
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);
}
//找约数
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;
}
}
总结
边栏推荐
- [RequireComponent(typeof(....))]
- 新兴市场潜力无限,ADVANCE.AI风控产品助中国出海企业筑牢安全发展基础
- win10下mysql改密码后,突然登录不上的问题解决过程记录
- The potential of emerging markets is unlimited, and advance.ai risk control products help Chinese offshore enterprises build a solid foundation for safe development
- Operating guidelines and suggestions for spot gold (Part 1)
- 什么是 Base64 ?
- v-model语法糖的实现
- Promise me, don't write shit code after reading it..
- 挖财钱堂和启牛学堂哪个更好一些?是安全的吗
- 小白学习MySQL - Derived Table
猜你喜欢

SQL注入 Less26(过滤空格和注释符,使用不带空格的报错注入)

Nacos作为注册中心、配置中心入门使用篇-实现远程调用、动态获取配置文件、数据库配置信息

OPPO 自研大规模知识图谱及其在数智工程中的应用

matlab 画短时平均幅度谱

08.02 邻接表

30000 hair loss people, supporting an IPO

Excel-vba quick start (X. prompt box, inputable pop-up box)

Matlab draws short-term average amplitude spectrum

博途PLC输出通道映射FC

Schematic diagram of MOS tube
随机推荐
Chapter 15 MySQL user management
Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
博客园美化技巧汇总
TASK04|分类分析
Try new functions | decrypt Doris complex data type array
挖财钱堂和启牛学堂哪个更好一些?是安全的吗
Xshell7 personal free download, use
matlab 激励模型 三角波频谱
30000 hair loss people, supporting an IPO
Do you know why to design test cases after learning so long about use case design
08.02 adjacency table
Let Xiaobai thoroughly understand performance tuning
06 CP command
Qt中为工程添加资源文件、给按钮添加图片
Proto basic grammar of protobuf
07 df 命令
xshell7个人免费下载,使用
Financial institution map
国信证券手机开户收费吗?开户安全吗?
LeetCode 121:买卖股票的最佳时机