Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
住在阳光的心里
skill_tree_dailycode
提交
45858ce0
S
skill_tree_dailycode
项目概览
住在阳光的心里
/
skill_tree_dailycode
与 Fork 源项目一致
Fork自
CSDN 技术社区 / skill_tree_dailycode
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_dailycode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
45858ce0
编写于
12月 07, 2021
作者:
每日一练社区
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add 3 exercises
上级
4f66165b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
247 addition
and
87 deletion
+247
-87
data/2.dailycode中阶/1.cpp/19.exercises/solution.md
data/2.dailycode中阶/1.cpp/19.exercises/solution.md
+54
-22
data/2.dailycode中阶/1.cpp/20.exercises/solution.md
data/2.dailycode中阶/1.cpp/20.exercises/solution.md
+133
-45
data/2.dailycode中阶/1.cpp/21.exercises/solution.md
data/2.dailycode中阶/1.cpp/21.exercises/solution.md
+60
-20
未找到文件。
data/2.dailycode中阶/1.cpp/19.exercises/solution.md
浏览文件 @
45858ce0
# 字符图形输出
编程实现把输入任意整数n后,可打印出n行三角字符阵列图形。例如,输入整数5时,程序运行结果如下:
```
json
ENTER
A
NUMBER:
5
<回车>
A
C
F
J
O
B
E
I
N
D
H
M
G
L
K
```
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <iostream>
using
namespace
std
;
char
a
[
100
][
100
];
int
main
()
{
char
c
=
'A'
;
int
n
=
5
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
i
;
j
>=
0
;
j
--
)
{
_______________
;
}
}
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
0
;
j
<
n
-
i
;
j
++
)
{
cout
<<
a
[
i
][
j
]
<<
" "
;
}
cout
<<
endl
;
}
}
```
## template
```
cpp
#include <iostream>
#include <iostream>
using
namespace
std
;
char
a
[
100
][
100
];
int
main
()
{
char
c
=
'A'
;
int
n
=
5
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
i
;
j
>=
0
;
j
--
)
{
a
[
j
][
i
-
j
]
=
c
++
;
}
}
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
0
;
j
<
n
-
i
;
j
++
)
{
cout
<<
a
[
i
][
j
]
<<
" "
;
}
cout
<<
endl
;
}
char
c
=
'A'
;
int
n
=
5
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
i
;
j
>=
0
;
j
--
)
{
a
[
j
][
i
-
j
]
=
c
++
;
}
}
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
0
;
j
<
n
-
i
;
j
++
)
{
cout
<<
a
[
i
][
j
]
<<
" "
;
}
cout
<<
endl
;
}
}
```
## 答案
```
cpp
a
[
j
][
i
-
j
]
=
c
++
;
```
## 选项
...
...
@@ -47,17 +78,17 @@ int main()
### A
```
cpp
a
[
j
][
i
]
=
c
++
;
```
### B
```
cpp
a
[
j
-
1
][
i
-
j
]
=
c
++
;
```
### C
```
cpp
a
[
j
][
i
-
1
]
=
c
++
;
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/20.exercises/solution.md
浏览文件 @
45858ce0
...
...
@@ -2,6 +2,48 @@
<p>
如何在一亿位整数组成的字符串中找到最长的递增数字字符串
?
</p>
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100000
int
main
()
{
char
buf
[
MAX_SIZE
]
=
{
0
};
int
i
=
0
,
len
=
0
,
index
=
0
;
char
maxbuf
[
12
]
=
{
0
};
char
maxbuf2
[
12
]
=
{
0
};
int
maxlen
=
0
;
gets
(
buf
);
len
=
strlen
(
buf
);
maxbuf2
[
0
]
=
buf
[
0
];
i
=
1
;
index
=
1
;
while
(
i
<
len
)
{
if
(
buf
[
i
]
>
buf
[
i
-
1
])
{
maxbuf2
[
index
]
=
buf
[
i
];
index
++
;
}
else
{
_________________
;
}
i
++
;
}
if
(
index
>
maxlen
)
{
maxlen
=
index
;
strcpy
(
maxbuf
,
maxbuf2
);
maxbuf
[
index
]
=
'\0'
;
}
printf
(
"最大串长度:%d,字符串:%s
\n
"
,
maxlen
,
maxbuf
);
return
0
;
}
```
## template
```
cpp
...
...
@@ -10,54 +52,68 @@
#define MAX_SIZE 100000
int
main
()
{
char
buf
[
MAX_SIZE
]
=
{
0
};
int
i
=
0
,
len
=
0
,
index
=
0
;
char
maxbuf
[
12
]
=
{
0
};
char
maxbuf2
[
12
]
=
{
0
};
int
maxlen
=
0
;
gets
(
buf
);
len
=
strlen
(
buf
);
maxbuf2
[
0
]
=
buf
[
0
];
i
=
1
;
index
=
1
;
while
(
i
<
len
)
{
if
(
buf
[
i
]
>
buf
[
i
-
1
])
{
maxbuf2
[
index
]
=
buf
[
i
];
index
++
;
}
else
{
if
(
index
>
maxlen
)
{
maxlen
=
index
;
strcpy
(
maxbuf
,
maxbuf2
);
maxbuf
[
index
]
=
'\0'
;
maxbuf2
[
0
]
=
buf
[
i
];
index
=
1
;
}
else
{
maxbuf2
[
0
]
=
buf
[
i
];
index
=
1
;
}
}
i
++
;
}
if
(
index
>
maxlen
)
{
maxlen
=
index
;
strcpy
(
maxbuf
,
maxbuf2
);
maxbuf
[
index
]
=
'\0'
;
}
printf
(
"最大串长度:%d,字符串:%s
\n
"
,
maxlen
,
maxbuf
);
return
0
;
char
buf
[
MAX_SIZE
]
=
{
0
};
int
i
=
0
,
len
=
0
,
index
=
0
;
char
maxbuf
[
12
]
=
{
0
};
char
maxbuf2
[
12
]
=
{
0
};
int
maxlen
=
0
;
gets
(
buf
);
len
=
strlen
(
buf
);
maxbuf2
[
0
]
=
buf
[
0
];
i
=
1
;
index
=
1
;
while
(
i
<
len
)
{
if
(
buf
[
i
]
>
buf
[
i
-
1
])
{
maxbuf2
[
index
]
=
buf
[
i
];
index
++
;
}
else
{
if
(
index
>
maxlen
)
{
maxlen
=
index
;
strcpy
(
maxbuf
,
maxbuf2
);
maxbuf
[
index
]
=
'\0'
;
maxbuf2
[
0
]
=
buf
[
i
];
index
=
1
;
}
else
{
maxbuf2
[
0
]
=
buf
[
i
];
index
=
1
;
}
}
i
++
;
}
if
(
index
>
maxlen
)
{
maxlen
=
index
;
strcpy
(
maxbuf
,
maxbuf2
);
maxbuf
[
index
]
=
'\0'
;
}
printf
(
"最大串长度:%d,字符串:%s
\n
"
,
maxlen
,
maxbuf
);
return
0
;
}
```
## 答案
```
cpp
if
(
index
>
maxlen
)
{
maxlen
=
index
;
strcpy
(
maxbuf
,
maxbuf2
);
maxbuf
[
index
]
=
'\0'
;
maxbuf2
[
0
]
=
buf
[
i
];
index
=
1
;
}
else
{
maxbuf2
[
0
]
=
buf
[
i
];
index
=
1
;
}
```
## 选项
...
...
@@ -65,17 +121,48 @@ int main()
### A
```
cpp
if
(
index
>
maxlen
)
{
maxlen
=
index
;
strcpy
(
maxbuf
,
maxbuf2
);
maxbuf
[
index
]
=
'\0'
;
maxbuf2
[
0
]
=
buf
[
i
];
index
=
1
;
}
```
### B
```
cpp
if
(
index
>
maxlen
)
{
maxlen
=
index
;
strcpy
(
maxbuf
,
maxbuf2
);
maxbuf
[
index
]
=
'\0'
;
maxbuf2
[
0
]
=
buf
[
i
];
index
++
;
}
else
{
maxbuf2
[
0
]
=
buf
[
i
];
index
++
;
}
```
### C
```
cpp
if
(
index
>
maxlen
)
{
maxlen
=
index
;
strcpy
(
maxbuf
,
maxbuf2
);
maxbuf
[
index
]
=
'\0'
;
maxbuf2
[
0
]
=
buf
[
i
];
index
=
0
;
}
else
{
maxbuf2
[
0
]
=
buf
[
i
];
index
=
0
;
}
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/21.exercises/solution.md
浏览文件 @
45858ce0
...
...
@@ -2,35 +2,62 @@
举例如下:一个数组{915,941,960,976,992,1015,1034,1050,1073,1089,1115,1131,1150,1166,1182,1208,1227};目标值假设是1000,最接近元素为992,下标为4
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
int
main
()
{
int
min
=
(
1
<<
31
)
-
1
;
int
idx
=
0
;
int
arr
[]
=
{
915
,
941
,
960
,
976
,
992
,
1015
,
1034
,
1050
,
1073
,
1089
,
1115
,
1131
,
1150
,
1166
,
1182
,
1208
,
1227
};
int
n
=
1000
;
for
(
int
i
=
0
;
i
<
sizeof
(
arr
)
/
sizeof
(
int
);
i
++
)
{
int
diff
=
arr
[
i
]
-
n
;
if
(
diff
<
0
)
diff
=
-
diff
;
_________________
;
}
printf
(
"最接近的是%d 下标是%d"
,
arr
[
idx
],
idx
);
return
0
;
}
```
## template
```
cpp
#include <stdio.h>
int
main
()
{
int
min
=
(
1
<<
31
)
-
1
;
int
idx
=
0
;
int
arr
[]
=
{
915
,
941
,
960
,
976
,
992
,
1015
,
1034
,
1050
,
1073
,
1089
,
1115
,
1131
,
1150
,
1166
,
1182
,
1208
,
1227
};
int
n
=
1000
;
for
(
int
i
=
0
;
i
<
sizeof
(
arr
)
/
sizeof
(
int
);
i
++
)
{
int
diff
=
arr
[
i
]
-
n
;
if
(
diff
<
0
)
diff
=
-
diff
;
if
(
diff
<
min
)
{
min
=
diff
;
idx
=
i
;
}
}
printf
(
"最接近的是%d 下标是%d"
,
arr
[
idx
],
idx
);
return
0
;
int
min
=
(
1
<<
31
)
-
1
;
int
idx
=
0
;
int
arr
[]
=
{
915
,
941
,
960
,
976
,
992
,
1015
,
1034
,
1050
,
1073
,
1089
,
1115
,
1131
,
1150
,
1166
,
1182
,
1208
,
1227
};
int
n
=
1000
;
for
(
int
i
=
0
;
i
<
sizeof
(
arr
)
/
sizeof
(
int
);
i
++
)
{
int
diff
=
arr
[
i
]
-
n
;
if
(
diff
<
0
)
diff
=
-
diff
;
if
(
diff
<
min
)
{
min
=
diff
;
idx
=
i
;
}
}
printf
(
"最接近的是%d 下标是%d"
,
arr
[
idx
],
idx
);
return
0
;
}
```
## 答案
```
cpp
if
(
diff
<
min
)
{
min
=
diff
;
idx
=
i
;
}
```
## 选项
...
...
@@ -38,17 +65,29 @@ int main()
### A
```
cpp
if
(
diff
>
min
)
{
min
=
diff
;
idx
=
i
;
}
```
### B
```
cpp
if
(
diff
>=
min
)
{
min
=
diff
;
idx
=
i
;
}
```
### C
```
cpp
if
(
diff
==
min
)
{
min
=
diff
;
idx
=
i
;
}
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录