Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_dailycode
提交
4f66165b
S
skill_tree_dailycode
项目概览
CSDN 技术社区
/
skill_tree_dailycode
通知
11
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_dailycode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
“a698824a8a298db15624873f5f54cbf7e6d818c5”上不存在“...paddle/v2/dataset/git@gitcode.net:RobotFutures/Paddle.git”
提交
4f66165b
编写于
12月 07, 2021
作者:
每日一练社区
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add 12 exercises
上级
69d23ffc
变更
20
显示空白变更内容
内联
并排
Showing
20 changed file
with
1216 addition
and
219 deletion
+1216
-219
data/1.dailycode初阶/1.cpp/30.exercises/solution.md
data/1.dailycode初阶/1.cpp/30.exercises/solution.md
+64
-9
data/1.dailycode初阶/1.cpp/31.exercises/solution.md
data/1.dailycode初阶/1.cpp/31.exercises/solution.md
+24
-1
data/2.dailycode中阶/1.cpp/1.exercises/solution.md
data/2.dailycode中阶/1.cpp/1.exercises/solution.md
+55
-5
data/2.dailycode中阶/1.cpp/10.exercises/solution.md
data/2.dailycode中阶/1.cpp/10.exercises/solution.md
+48
-13
data/2.dailycode中阶/1.cpp/11.exercises/solution.md
data/2.dailycode中阶/1.cpp/11.exercises/solution.md
+59
-15
data/2.dailycode中阶/1.cpp/12.exercises/solution.md
data/2.dailycode中阶/1.cpp/12.exercises/solution.md
+124
-25
data/2.dailycode中阶/1.cpp/13.exercises/solution.md
data/2.dailycode中阶/1.cpp/13.exercises/solution.md
+89
-19
data/2.dailycode中阶/1.cpp/14.exercises/solution.md
data/2.dailycode中阶/1.cpp/14.exercises/solution.md
+66
-11
data/2.dailycode中阶/1.cpp/15.exercises/solution.md
data/2.dailycode中阶/1.cpp/15.exercises/solution.md
+74
-29
data/2.dailycode中阶/1.cpp/16.exercises/solution.md
data/2.dailycode中阶/1.cpp/16.exercises/solution.md
+54
-5
data/2.dailycode中阶/1.cpp/17.exercises/solution.md
data/2.dailycode中阶/1.cpp/17.exercises/solution.md
+65
-15
data/2.dailycode中阶/1.cpp/18.exercises/solution.md
data/2.dailycode中阶/1.cpp/18.exercises/solution.md
+70
-10
data/2.dailycode中阶/1.cpp/2.exercises/solution.md
data/2.dailycode中阶/1.cpp/2.exercises/solution.md
+45
-4
data/2.dailycode中阶/1.cpp/3.exercises/solution.md
data/2.dailycode中阶/1.cpp/3.exercises/solution.md
+28
-1
data/2.dailycode中阶/1.cpp/4.exercises/solution.md
data/2.dailycode中阶/1.cpp/4.exercises/solution.md
+30
-1
data/2.dailycode中阶/1.cpp/5.exercises/solution.md
data/2.dailycode中阶/1.cpp/5.exercises/solution.md
+40
-1
data/2.dailycode中阶/1.cpp/6.exercises/solution.md
data/2.dailycode中阶/1.cpp/6.exercises/solution.md
+34
-1
data/2.dailycode中阶/1.cpp/7.exercises/solution.md
data/2.dailycode中阶/1.cpp/7.exercises/solution.md
+93
-20
data/2.dailycode中阶/1.cpp/8.exercises/solution.md
data/2.dailycode中阶/1.cpp/8.exercises/solution.md
+115
-30
data/2.dailycode中阶/1.cpp/9.exercises/solution.md
data/2.dailycode中阶/1.cpp/9.exercises/solution.md
+39
-4
未找到文件。
data/1.dailycode初阶/1.cpp/30.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -2,7 +2,7 @@
1,2,4,2,3,6,12,6,3,....求第n项值
## template
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
...
...
@@ -50,16 +50,70 @@ int main()
}
```
##
答案
##
template
```
cpp
for
(
i
=
2
;
i
<=
(
*
y
);
i
++
)
#include <stdio.h>
int
fun
(
int
n
,
int
*
x
,
int
*
y
)
{
int
sum
=
0
,
i
;
int
size
=
0
;
int
dd
=
1
;
for
(
i
=
1
;
i
<=
(
*
x
);
i
++
)
{
sum
+=
(
2
*
i
-
1
);
}
if
(
sum
==
n
)
{
*
y
=
2
*
(
*
x
)
-
1
;
return
(
*
x
);
}
else
if
(
sum
>
n
)
{
(
*
y
)
=
n
-
(
sum
-
(
2
*
(
*
x
)
-
1
));
size
=
2
*
(
*
x
)
-
1
;
dd
=
(
*
x
);
for
(
i
=
2
;
i
<=
(
*
y
);
i
++
)
for
(
i
=
2
;
i
<=
(
*
y
);
i
++
)
{
if
(
i
<=
(
*
x
))
dd
*=
2
;
else
dd
/=
2
;
}
return
dd
;
}
else
{
(
*
x
)
++
;
return
fun
(
n
,
x
,
y
);
}
}
int
main
()
{
int
n
;
int
row
=
1
,
col
=
0
;
int
val
;
row
=
1
;
col
=
0
;
printf
(
"请输入n:"
);
scanf
(
"%d"
,
&
n
);
val
=
fun
(
n
,
&
row
,
&
col
);
printf
(
"第%d项是:%d
\n
"
,
n
,
val
);
return
0
;
}
```
## 答案
```
cpp
for
(
i
=
2
;
i
<=
(
*
y
);
i
++
)
{
if
(
i
<=
(
*
x
))
dd
*=
2
;
else
dd
/=
2
;
}
```
## 选项
...
...
@@ -68,34 +122,34 @@ for (i = 2; i <= (*y); i++)
```
cpp
for
(
i
=
2
;
i
<=
(
*
y
);
i
++
)
{
{
if
(
i
<=
(
*
x
))
dd
/=
2
;
else
dd
*=
2
;
}
}
```
### B
```
cpp
for
(
i
=
2
;
i
<=
(
*
y
);
i
++
)
{
{
if
(
i
<=
(
*
x
))
dd
+=
2
;
else
dd
-=
2
;
}
}
```
### C
```
cpp
for
(
i
=
2
;
i
<=
(
*
y
);
i
++
)
{
{
if
(
i
<=
(
*
x
))
dd
-=
2
;
else
dd
+=
2
;
}
}
```
\ No newline at end of file
data/1.dailycode初阶/1.cpp/31.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -2,7 +2,7 @@
例如:字符串中的内容为:a1Ab1D2,1<A,A<b 1<D 则调用该函数后,返回码为:3。
## template
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <iostream>
...
...
@@ -25,6 +25,29 @@ int main()
}
```
## template
```
cpp
#include <iostream>
#include <string>
using
namespace
std
;
int
solve
(
string
s
)
{
if
(
s
.
length
()
==
0
)
return
0
;
int
n
=
0
;
for
(
int
i
=
1
;
i
<
s
.
length
();
i
++
)
if
(
s
.
c_str
()[
i
]
<
s
.
c_str
()[
i
-
1
])
n
++
;
return
n
;
}
int
main
()
{
string
s
=
"a1Ab1D2"
;
int
n
=
solve
(
s
);
cout
<<
n
<<
endl
;
return
0
;
}
```
## 答案
```
cpp
...
...
data/2.dailycode中阶/1.cpp/1.exercises/solution.md
浏览文件 @
4f66165b
# 移动字符串
给定一个字符串长度为 nn 的字符串 s1 (10<n<100) , 求出将字符串循环向左移动 k 位的字符串 s2 (1<k<n) , 例如:字符串 abcdefghijk , 循环向左移动 3 位就变成 defghijkabc
输入描述
**输入描述**
输入仅两行,第一行为左移的位数 k , 第二行为字符串 s1 .
输出描述
**输出描述**
输出仅一行,为将字符串 s1 左移 k 位得到的字符串 s2 .
样例输入
**样例输入**
```
json
3
abcdefghijk
样例输出
```
**样例输出**
```
json
defghijkabc
```
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <iostream>
#include <string.h>
using
namespace
std
;
void
reverse
(
char
*
a
,
int
start
,
int
end
)
{
int
i
,
j
,
temp
;
for
(
i
=
start
,
j
=
end
;
i
<
j
;
i
++
,
j
--
)
{
temp
=
a
[
i
];
a
[
i
]
=
a
[
j
];
a
[
j
]
=
temp
;
}
}
void
turnleft
(
char
*
a
,
int
i
,
int
n
)
{
int
left
=
i
%
n
;
if
(
left
==
0
)
return
;
______________
;
return
;
}
int
main
()
{
char
a
[
1024
];
int
i
;
cin
>>
i
;
cin
>>
a
;
int
n
=
strlen
(
a
);
turnleft
(
a
,
i
,
n
);
cout
<<
a
<<
endl
;
}
```
## template
...
...
@@ -32,7 +80,9 @@ void turnleft(char *a, int i, int n)
int
left
=
i
%
n
;
if
(
left
==
0
)
return
;
______________
reverse
(
a
,
0
,
left
-
1
);
reverse
(
a
,
left
,
n
-
1
);
reverse
(
a
,
0
,
n
-
1
);
return
;
}
int
main
()
...
...
data/2.dailycode中阶/1.cpp/10.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -2,31 +2,61 @@
<pre>
一个数如果恰好等于它的所有因子之和
,
这个数就称为“完数”。统计自然数 1 — 100 间完数的个数。
</pre>
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
int
perfect
()
{
int
i
,
x
,
sum
,
cnt
=
0
;
for
(
i
=
1
;
i
<=
100
;
i
++
)
{
sum
=
0
;
for
(
x
=
1
;
x
<
i
;
x
++
)
{
_____________
;
}
if
(
i
==
sum
)
{
cnt
++
;
printf
(
"%d "
,
i
);
}
}
return
cnt
;
}
int
main
()
{
printf
(
"
\n
count=%d
\n
"
,
perfect
());
return
0
;
}
```
## template
```
cpp
#include<stdio.h>
#include
<stdio.h>
int
perfect
()
{
int
i
,
x
,
sum
,
cnt
=
0
;
for
(
i
=
1
;
i
<=
100
;
i
++
)
int
i
,
x
,
sum
,
cnt
=
0
;
for
(
i
=
1
;
i
<=
100
;
i
++
)
{
sum
=
0
;
for
(
x
=
1
;
x
<
i
;
x
++
)
sum
=
0
;
for
(
x
=
1
;
x
<
i
;
x
++
)
{
if
(
i
%
x
==
0
)
sum
+=
x
;
if
(
i
%
x
==
0
)
sum
+=
x
;
}
if
(
i
==
sum
)
if
(
i
==
sum
)
{
cnt
++
;
printf
(
"%d "
,
i
);
printf
(
"%d "
,
i
);
}
}
return
cnt
;
}
int
main
()
{
printf
(
"
\n
count=%d
\n
"
,
perfect
());
printf
(
"
\n
count=%d
\n
"
,
perfect
());
return
0
;
}
```
...
...
@@ -34,7 +64,8 @@ int main()
## 答案
```
cpp
if
(
i
/
x
==
0
)
sum
+=
x
;
```
## 选项
...
...
@@ -42,17 +73,20 @@ int main()
### A
```
cpp
if
(
i
-
x
==
0
)
sum
+=
x
;
```
### B
```
cpp
if
(
i
%
x
==
1
)
sum
+=
x
;
```
### C
```
cpp
if
(
i
/
x
==
1
)
sum
+=
x
;
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/11.exercises/solution.md
浏览文件 @
4f66165b
# 好数对
已知一个集合A,对A中任意两个不同的元素求和,若求得的和仍在A内,则称其为好数对。例如,集合A={1 2 3 4},1+2=3,1+3=4,则1,2和1,3 是两个好数对。编写程序求给定集合中好数对的个数。
注:集合中最多有1000个元素,元素最大不超过10000
程序运行示例1:
```
json
4
↙
1
2
3
4
↙
2
```
程序运行示例2:
```
json
7
↙
2456
3251
654
890
100
754
1234
↙
1
```
其中,“↙”表示输入
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
#include <stdlib.h>
int
main
()
{
int
n
,
i
,
j
,
t
;
scanf
(
"%d"
,
&
n
);
int
*
a
=
(
int
*
)
malloc
(
n
*
sizeof
(
int
));
for
(
i
=
0
;
i
<
n
;
i
++
)
{
scanf
(
"%d"
,
&
a
[
i
]);
}
int
cout
=
0
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
j
=
i
+
1
;
j
<
n
;
j
++
)
{
for
(
t
=
0
;
t
<
n
;
t
++
)
____________
;
}
}
printf
(
"%d"
,
cout
);
free
(
a
);
return
0
;
}
```
## template
```
cpp
...
...
@@ -19,24 +58,24 @@
#include <stdlib.h>
int
main
()
{
int
n
,
i
,
j
,
t
;
scanf
(
"%d"
,
&
n
);
int
*
a
=
(
int
*
)
malloc
(
n
*
sizeof
(
int
));
for
(
i
=
0
;
i
<
n
;
i
++
)
int
n
,
i
,
j
,
t
;
scanf
(
"%d"
,
&
n
);
int
*
a
=
(
int
*
)
malloc
(
n
*
sizeof
(
int
));
for
(
i
=
0
;
i
<
n
;
i
++
)
{
scanf
(
"%d"
,
&
a
[
i
]);
scanf
(
"%d"
,
&
a
[
i
]);
}
int
cout
=
0
;
for
(
i
=
0
;
i
<
n
;
i
++
)
int
cout
=
0
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
j
=
i
+
1
;
j
<
n
;
j
++
)
for
(
j
=
i
+
1
;
j
<
n
;
j
++
)
{
for
(
t
=
0
;
t
<
n
;
t
++
)
if
(
a
[
i
]
+
a
[
j
]
==
a
[
t
])
for
(
t
=
0
;
t
<
n
;
t
++
)
if
(
a
[
i
]
+
a
[
j
]
==
a
[
t
])
cout
++
;
}
}
printf
(
"%d"
,
cout
);
printf
(
"%d"
,
cout
);
free
(
a
);
return
0
;
}
...
...
@@ -45,7 +84,8 @@ int main()
## 答案
```
cpp
if
(
a
[
i
]
+
a
[
j
]
==
a
[
t
])
cout
++
;
```
## 选项
...
...
@@ -53,17 +93,20 @@ int main()
### A
```
cpp
if
(
a
[
i
]
+
a
[
j
]
<=
a
[
t
])
cout
++
;
```
### B
```
cpp
if
(
a
[
i
]
+
a
[
j
]
>=
a
[
t
])
cout
++
;
```
### C
```
cpp
if
(
a
[
i
]
+
a
[
j
]
<
a
[
t
])
cout
++
;
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/12.exercises/solution.md
浏览文件 @
4f66165b
# 难倒数万人的小学数学题
汉堡包在大街上大摇大摆的走着,看着手机上一道难倒数万人的小学数学题:
```
json
1
+
1
=
0
1
+
6
=
1
6
+
6
=
2
8
+
1
=
2
8
+
6
=
3
```
汉堡包看完之后发现上面这些加法的答案就是看1,6,8中圈圈的个数嘛!
突然之间,所有大厦上的LED屏幕上的广告全部变成数字1,6,8三个数字的随机闪现。
现给你一块n
*
m的LED屏幕,上面有且仅有一个数字(1,6,or 8),请你输出你看见的那个字母。
输入格式:
**输入格式:**
第一行输入两个整数n,m(2<= m, n <= 1000);
接下来n行,每行由m个数字0和1组成,其中1表示数字1,6,8的组成部分。
输出格式:
**输出格式:**
输出一个整数,代表图形表示的数字。
输入样例:
**输入样例:**
```
json
7
7
0
0
0
0
0
0
0
0
0
1
1
1
0
0
...
...
@@ -23,8 +37,56 @@
0
0
1
0
1
0
0
0
0
1
1
1
0
0
0
0
0
0
0
0
0
输出样例:
```
**输出样例:**
```
json
8
```
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
using
namespace
std
;
int
main
()
{
int
i
,
j
,
k
=
1
;
int
n
,
m
;
int
num
[
1010
]
=
{
0
};
int
num_cmp
=
0
;
int
flag
=
1
;
int
led
[
1005
][
1005
];
cin
>>
n
>>
m
;
for
(
i
=
1
;
i
<=
n
;
i
++
)
{
for
(
j
=
1
;
j
<=
m
;
j
++
)
{
cin
>>
led
[
i
][
j
];
if
(
led
[
i
][
j
]
==
1
)
num
[
k
]
++
;
}
if
(
num
[
k
]
!=
0
)
k
++
;
}
num_cmp
=
num
[
k
-
1
];
______________________
;
if
(
flag
==
1
)
cout
<<
"1"
<<
endl
;
else
if
(
flag
==
2
)
cout
<<
"8"
<<
endl
;
else
cout
<<
"6"
<<
endl
;
return
0
;
}
```
## template
...
...
@@ -37,31 +99,41 @@
#include <stack>
#include <queue>
using
namespace
std
;
int
main
(){
int
i
,
j
,
k
=
1
;
int
n
,
m
;
int
num
[
1010
]
=
{
0
};
int
num_cmp
=
0
;
int
flag
=
1
;
int
main
()
{
int
i
,
j
,
k
=
1
;
int
n
,
m
;
int
num
[
1010
]
=
{
0
};
int
num_cmp
=
0
;
int
flag
=
1
;
int
led
[
1005
][
1005
];
cin
>>
n
>>
m
;
for
(
i
=
1
;
i
<=
n
;
i
++
){
for
(
j
=
1
;
j
<=
m
;
j
++
){
for
(
i
=
1
;
i
<=
n
;
i
++
)
{
for
(
j
=
1
;
j
<=
m
;
j
++
)
{
cin
>>
led
[
i
][
j
];
if
(
led
[
i
][
j
]
==
1
)
num
[
k
]
++
;
if
(
led
[
i
][
j
]
==
1
)
num
[
k
]
++
;
}
if
(
num
[
k
]
!=
0
)
k
++
;
if
(
num
[
k
]
!=
0
)
k
++
;
}
num_cmp
=
num
[
k
-
1
];
for
(
i
=
k
-
1
;
i
>
0
;
i
--
){
if
(
num
[
i
]
<
num_cmp
)
{
num_cmp
=
num
[
k
-
1
];
for
(
i
=
k
-
1
;
i
>
0
;
i
--
)
{
if
(
num
[
i
]
<
num_cmp
)
{
flag
++
;
num_cmp
=
num
[
i
];
num_cmp
=
num
[
i
];
}
}
if
(
flag
==
1
)
cout
<<
"1"
<<
endl
;
else
if
(
flag
==
2
)
cout
<<
"8"
<<
endl
;
else
cout
<<
"6"
<<
endl
;
if
(
flag
==
1
)
cout
<<
"1"
<<
endl
;
else
if
(
flag
==
2
)
cout
<<
"8"
<<
endl
;
else
cout
<<
"6"
<<
endl
;
return
0
;
}
```
...
...
@@ -69,7 +141,14 @@ int main(){
## 答案
```
cpp
for
(
i
=
k
-
1
;
i
>
0
;
i
--
)
{
if
(
num
[
i
]
<
num_cmp
)
{
flag
++
;
num_cmp
=
num
[
i
];
}
}
```
## 选项
...
...
@@ -77,17 +156,36 @@ int main(){
### A
```
cpp
for
(
i
=
k
-
1
;
i
>
0
;
i
--
)
{
if
(
num
[
i
]
<
num_cmp
)
{
flag
++
;
}
}
```
### B
```
cpp
for
(
i
=
k
-
1
;
i
>
0
;
i
--
)
{
if
(
num
[
i
]
<
num_cmp
)
{
num_cmp
=
num
[
i
];
}
}
```
### C
```
cpp
for
(
i
=
k
-
1
;
i
>
0
;
i
--
)
{
if
(
num
[
i
]
>
num_cmp
)
{
flag
++
;
num_cmp
=
num
[
i
];
}
}
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/13.exercises/solution.md
浏览文件 @
4f66165b
# 约分
编写程序,要求用户输入一个分数,然后将其约分为最简式。如:
输入一个分数:8/12
最简分式:2/3
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
#include <stdlib.h>
int
main
()
{
int
a
,
b
,
x
,
y
,
c
;
printf
(
"输入一个分式:"
);
scanf
(
"%d/%d"
,
&
a
,
&
b
);
_________________
;
while
(
c
)
{
x
=
y
;
y
=
c
;
c
=
x
%
y
;
}
if
(
b
/
y
!=
1
)
printf
(
"最简分式为:%d/%d"
,
a
/
y
,
b
/
y
);
else
printf
(
"最简分式为:%d"
,
a
/
y
);
return
0
;
}
```
## template
```
cpp
#include<stdio.h>
#include<stdlib.h>
#include
<stdio.h>
#include
<stdlib.h>
int
main
()
{
int
a
,
b
,
x
,
y
,
c
;
int
a
,
b
,
x
,
y
,
c
;
printf
(
"输入一个分式:"
);
scanf
(
"%d/%d"
,
&
a
,
&
b
);
if
(
a
<
b
)
scanf
(
"%d/%d"
,
&
a
,
&
b
);
if
(
a
<
b
)
{
x
=
b
;
y
=
a
;
x
=
b
;
y
=
a
;
}
else
{
x
=
a
;
y
=
b
;
x
=
a
;
y
=
b
;
}
c
=
x
%
y
;
while
(
c
)
c
=
x
%
y
;
while
(
c
)
{
x
=
y
;
y
=
c
;
c
=
x
%
y
;
x
=
y
;
y
=
c
;
c
=
x
%
y
;
}
if
(
b
/
y
!=
1
)
printf
(
"最简分式为:%d/%d"
,
a
/
y
,
b
/
y
);
if
(
b
/
y
!=
1
)
printf
(
"最简分式为:%d/%d"
,
a
/
y
,
b
/
y
);
else
printf
(
"最简分式为:%d"
,
a
/
y
);
printf
(
"最简分式为:%d"
,
a
/
y
);
return
0
;
}
```
...
...
@@ -40,7 +69,17 @@ int main()
## 答案
```
cpp
if
(
a
<
b
)
{
x
=
b
;
y
=
a
;
}
else
{
x
=
a
;
y
=
b
;
}
c
=
x
%
y
;
```
## 选项
...
...
@@ -48,17 +87,47 @@ int main()
### A
```
cpp
if
(
a
<
b
)
{
x
=
a
;
y
=
b
;
}
else
{
x
=
b
;
y
=
a
;
}
c
=
x
%
y
;
```
### B
```
cpp
if
(
a
<
b
)
{
x
=
a
;
y
=
b
;
}
else
{
x
=
b
;
y
=
a
;
}
c
=
x
/
y
;
```
### C
```
cpp
if
(
a
<
b
)
{
x
=
b
;
y
=
a
;
}
else
{
x
=
a
;
y
=
b
;
}
c
=
x
/
y
;
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/14.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -2,32 +2,70 @@
输入若干英文单词,将每个单词的首字母转换成大写字母,其他字母为小写,并按字典顺序排列
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
cmp
(
const
void
*
a
,
const
void
*
b
)
{
return
strcmp
(
*
(
char
**
)
a
,
*
(
char
**
)
b
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
n
=
0
;
int
i
;
printf
(
"how many words?
\n
"
);
scanf
(
"%d"
,
&
n
);
char
**
s
=
new
char
*
[
n
];
for
(
i
=
0
;
i
<
n
;
i
++
)
{
s
[
i
]
=
new
char
[
100
];
scanf
(
"%s"
,
s
[
i
]);
char
*
t
=
s
[
i
];
while
(
*
t
!=
'\0'
)
{
_______________
;
}
}
qsort
(
s
,
n
,
sizeof
(
char
*
),
cmp
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
printf
(
"%s
\n
"
,
s
[
i
]);
}
return
0
;
}
```
## template
```
cpp
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
cmp
(
const
void
*
a
,
const
void
*
b
)
int
cmp
(
const
void
*
a
,
const
void
*
b
)
{
return
strcmp
(
*
(
char
**
)
a
,
*
(
char
**
)
b
);
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
int
n
=
0
;
int
i
;
printf
(
"how many words?
\n
"
);
scanf
(
"%d"
,
&
n
);
char
**
s
=
new
char
*
[
n
];
char
**
s
=
new
char
*
[
n
];
for
(
i
=
0
;
i
<
n
;
i
++
)
{
s
[
i
]
=
new
char
[
100
];
scanf
(
"%s"
,
s
[
i
]);
char
*
t
=
s
[
i
];
char
*
t
=
s
[
i
];
while
(
*
t
!=
'\0'
)
{
if
(
t
==
s
[
i
]
&&
(
*
t
>=
'a'
&&
*
t
<=
'z'
))
*
t
=
*
t
-
'a'
+
'A'
;
if
(
t
>
s
[
i
]
&&
(
*
t
>=
'A'
&&
*
t
<=
'Z'
))
*
t
=
*
t
-
'A'
+
'a'
;
if
(
t
==
s
[
i
]
&&
(
*
t
>=
'a'
&&
*
t
<=
'z'
))
*
t
=
*
t
-
'a'
+
'A'
;
if
(
t
>
s
[
i
]
&&
(
*
t
>=
'A'
&&
*
t
<=
'Z'
))
*
t
=
*
t
-
'A'
+
'a'
;
t
++
;
}
}
...
...
@@ -43,7 +81,11 @@ int main(int argc, char* argv[])
## 答案
```
cpp
if
(
t
==
s
[
i
]
&&
(
*
t
>=
'a'
&&
*
t
<=
'z'
))
*
t
=
*
t
-
'a'
+
'A'
;
if
(
t
>
s
[
i
]
&&
(
*
t
>=
'A'
&&
*
t
<=
'Z'
))
*
t
=
*
t
-
'A'
+
'a'
;
t
++
;
```
## 选项
...
...
@@ -51,17 +93,29 @@ int main(int argc, char* argv[])
### A
```
cpp
if
(
t
==
s
[
i
]
&&
(
*
t
>=
'a'
&&
*
t
<=
'z'
))
t
=
t
-
'a'
+
'A'
;
if
(
t
>
s
[
i
]
&&
(
*
t
>=
'A'
&&
*
t
<=
'Z'
))
t
=
t
-
'A'
+
'a'
;
t
++
;
```
### B
```
cpp
if
(
t
==
s
[
i
]
&&
(
*
t
>=
'a'
&&
*
t
<=
'z'
))
t
=
t
-
'A'
+
'a'
;
if
(
t
>
s
[
i
]
&&
(
*
t
>=
'A'
&&
*
t
<=
'Z'
))
t
=
t
-
'a'
+
'A'
;
t
++
;
```
### C
```
cpp
if
(
t
==
s
[
i
]
&&
(
*
t
>=
'a'
&&
*
t
<=
'z'
))
*
t
=
*
t
-
'A'
+
'a'
;
if
(
t
>
s
[
i
]
&&
(
*
t
>=
'A'
&&
*
t
<=
'Z'
))
*
t
=
*
t
-
'a'
+
'A'
;
t
++
;
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/15.exercises/solution.md
浏览文件 @
4f66165b
# 国名排序
【字符数组】国名排序
Description:
**题目描述:**
小李在准备明天的广交会,明天有来自世界各国的客房跟他们谈生意,小李要尽快的整理出名单给经理,你能帮他把客户来自的国家按英文字典次序排好吗?
例如小李手上有来自加拿大,美国,中国的名单,排好的名单应是美国,加拿大,中国
Input
第一行为一个n(n<=100)表示n个国家,第2行到第n+1行分别为n个国家的名字.
Output
输出共计n行,为n个国家按字典顺序的排列,每行为一个国家
Sample Input:
3
China
Canada
America
Sample Output:
America
Canada
China
**输入**
第一行为一个n(n<=100)表示n个国家,第2行到第n+1行分别为n个国家的名字.
**输出**
输出共计n行,为n个国家按字典顺序的排列,每行为一个国家
**输入样例:**
```
json
3
China
Canada
America
```
**输出样例:**
```
json
America
Canada
China
```
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <iostream>
#include <string>
using
namespace
std
;
string
a
[
1000
];
int
main
()
{
int
i
,
n
;
cin
>>
n
;
for
(
i
=
1
;
i
<=
n
;
i
++
)
{
cin
>>
a
[
i
];
}
for
(
i
=
1
;
i
<=
n
;
i
++
)
{
for
(
int
j
=
i
+
1
;
j
<=
n
;
j
++
)
{
_________
;
}
}
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
cout
<<
a
[
i
]
<<
endl
;
return
0
;
}
```
## template
...
...
@@ -27,22 +67,22 @@ using namespace std;
string
a
[
1000
];
int
main
()
{
int
i
,
n
;
cin
>>
n
;
for
(
i
=
1
;
i
<=
n
;
i
++
)
int
i
,
n
;
cin
>>
n
;
for
(
i
=
1
;
i
<=
n
;
i
++
)
{
cin
>>
a
[
i
];
cin
>>
a
[
i
];
}
for
(
i
=
1
;
i
<=
n
;
i
++
)
for
(
i
=
1
;
i
<=
n
;
i
++
)
{
for
(
int
j
=
i
+
1
;
j
<=
n
;
j
++
)
for
(
int
j
=
i
+
1
;
j
<=
n
;
j
++
)
{
if
(
a
[
i
]
>
a
[
j
])
swap
(
a
[
i
],
a
[
j
]);
if
(
a
[
i
]
>
a
[
j
])
swap
(
a
[
i
],
a
[
j
]);
}
}
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
cout
<<
a
[
i
]
<<
endl
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
cout
<<
a
[
i
]
<<
endl
;
return
0
;
}
```
...
...
@@ -50,7 +90,8 @@ int main()
## 答案
```
cpp
if
(
a
[
i
]
>
a
[
j
])
swap
(
a
[
i
],
a
[
j
]);
```
## 选项
...
...
@@ -58,17 +99,20 @@ int main()
### A
```
cpp
if
(
a
[
i
]
<
a
[
j
])
swap
(
a
[
i
],
a
[
j
]);
```
### B
```
cpp
if
(
a
[
i
]
<=
a
[
j
])
swap
(
a
[
i
],
a
[
j
]);
```
### C
```
cpp
if
(
a
[
i
]
==
a
[
j
])
swap
(
a
[
i
],
a
[
j
]);
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/16.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -2,6 +2,22 @@
目前有一个长度为 n 的木棍,当做直角三角形的斜边。A,B,C要从许多整数长度的木棍中选出三根,分别长为 a, b, c。 现在,蒜头君和花椰妹的木棍组成一条直角边长度为 a + b,白菜君组成另外一条直角边 c,并且要求 a + b ≤ c。请问一共可以有多少种取木棍的方案。 提示:a = 3, b = 4 与 a = 4, b = 3 算作同一种方案。
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
int
main
()
{
int
n
;
int
cnt
=
0
;
scanf
(
"%d"
,
&
n
);
for
(
int
a
=
1
;
a
<
n
;
a
++
)
_______________
;
printf
(
"一共有%d种方案"
,
cnt
);
return
0
;
}
```
## template
```
cpp
...
...
@@ -15,7 +31,7 @@ int main()
for
(
int
b
=
a
;
b
<
n
-
a
;
b
++
)
for
(
int
c
=
1
;
c
<
n
;
c
++
)
{
if
((
a
+
b
)
*
(
a
+
b
)
+
c
*
c
==
n
*
n
)
if
((
a
+
b
)
*
(
a
+
b
)
+
c
*
c
==
n
*
n
)
{
printf
(
"a=%d b=%d c=%d
\n
"
,
a
,
b
,
c
);
cnt
++
;
...
...
@@ -29,7 +45,15 @@ int main()
## 答案
```
cpp
for
(
int
b
=
a
;
b
<
n
-
a
;
b
++
)
for
(
int
c
=
1
;
c
<
n
;
c
++
)
{
if
((
a
+
b
)
*
(
a
+
b
)
+
c
*
c
==
n
*
n
)
{
printf
(
"a=%d b=%d c=%d
\n
"
,
a
,
b
,
c
);
cnt
++
;
}
}
```
## 选项
...
...
@@ -37,17 +61,41 @@ int main()
### A
```
cpp
for
(
int
b
=
a
;
b
<
n
-
a
;
b
++
)
for
(
int
c
=
1
;
c
<
n
;
c
++
)
{
if
((
a
+
b
)
*
(
a
+
b
)
+
c
*
c
>=
n
*
n
)
{
printf
(
"a=%d b=%d c=%d
\n
"
,
a
,
b
,
c
);
cnt
++
;
}
}
```
### B
```
cpp
for
(
int
b
=
a
;
b
<
n
-
a
;
b
++
)
for
(
int
c
=
1
;
c
<
n
;
c
++
)
{
if
((
a
+
b
)
*
(
a
+
b
)
+
c
*
c
<=
n
*
n
)
{
printf
(
"a=%d b=%d c=%d
\n
"
,
a
,
b
,
c
);
cnt
++
;
}
}
```
### C
```
cpp
for
(
int
b
=
a
;
b
<
n
-
a
;
b
++
)
for
(
int
c
=
1
;
c
<
n
;
c
++
)
{
if
((
a
+
b
)
*
(
a
+
b
)
+
c
*
c
>
n
*
n
)
{
printf
(
"a=%d b=%d c=%d
\n
"
,
a
,
b
,
c
);
cnt
++
;
}
}
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/17.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -10,13 +10,51 @@
<strong>
输出
</strong><br
/>
输出共一行 m 个整数
,
表示每回合报出的编号
,
每两个整数之间一个空格
,
最后一个数后面没有空格。
</p>
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using
namespace
std
;
int
ai
[
100010
],
qi
[
100010
];
int
main
()
{
int
a
,
q
;
while
(
cin
>>
a
>>
q
)
{
for
(
int
i
=
0
;
i
<
a
;
i
++
)
cin
>>
ai
[
i
];
for
(
int
i
=
0
;
i
<
q
;
i
++
)
cin
>>
qi
[
i
];
for
(
int
i
=
0
;
i
<
q
;
i
++
)
{
int
left
=
0
,
right
=
a
-
1
,
mid
;
while
(
left
<
right
)
{
mid
=
(
left
+
right
)
>>
1
;
if
(
ai
[
mid
]
<=
qi
[
i
])
left
=
mid
+
1
;
else
right
=
mid
;
}
_______________________
;
i
?
cout
<<
" "
<<
ai
[
left
-
1
]
:
cout
<<
ai
[
left
-
1
];
}
cout
<<
endl
;
}
return
0
;
}
```
## template
```
cpp
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include
<iostream>
#include
<cstring>
#include
<vector>
#include
<algorithm>
using
namespace
std
;
int
ai
[
100010
],
qi
[
100010
];
int
main
()
...
...
@@ -24,16 +62,23 @@ int main()
int
a
,
q
;
while
(
cin
>>
a
>>
q
)
{
for
(
int
i
=
0
;
i
<
a
;
i
++
)
cin
>>
ai
[
i
];
for
(
int
i
=
0
;
i
<
q
;
i
++
)
cin
>>
qi
[
i
];
for
(
int
i
=
0
;
i
<
q
;
i
++
)
{
for
(
int
i
=
0
;
i
<
a
;
i
++
)
cin
>>
ai
[
i
];
for
(
int
i
=
0
;
i
<
q
;
i
++
)
cin
>>
qi
[
i
];
for
(
int
i
=
0
;
i
<
q
;
i
++
)
{
int
left
=
0
,
right
=
a
-
1
,
mid
;
while
(
left
<
right
)
{
while
(
left
<
right
)
{
mid
=
(
left
+
right
)
>>
1
;
if
(
ai
[
mid
]
<=
qi
[
i
])
left
=
mid
+
1
;
else
right
=
mid
;
if
(
ai
[
mid
]
<=
qi
[
i
])
left
=
mid
+
1
;
else
right
=
mid
;
}
if
(
left
-
1
<
0
||
ai
[
left
]
<
qi
[
i
])
left
++
;
if
(
left
-
1
<
0
||
ai
[
left
]
<
qi
[
i
])
left
++
;
i
?
cout
<<
" "
<<
ai
[
left
-
1
]
:
cout
<<
ai
[
left
-
1
];
}
cout
<<
endl
;
...
...
@@ -45,7 +90,8 @@ int main()
## 答案
```
cpp
if
(
left
-
1
<
0
||
ai
[
left
]
<
qi
[
i
])
left
++
;
```
## 选项
...
...
@@ -53,17 +99,20 @@ int main()
### A
```
cpp
if
(
left
-
1
<
0
)
left
++
;
```
### B
```
cpp
if
(
ai
[
left
]
<
qi
[
i
])
left
++
;
```
### C
```
cpp
if
(
left
-
1
<
0
&&
ai
[
left
]
<
qi
[
i
])
left
++
;
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/18.exercises/solution.md
浏览文件 @
4f66165b
# 不喜欢带钱的小C
题目描述:
**题目描述:**
小C不喜欢带钱,有一次竟被他碰上了一家不能使用移动支付(也不能找钱)的神秘商店。请问小C至少准备多少张RMB才能恰好支付n元。RMB的面额有100元,50元,20元,10元,5元,1元。
输入格式:
**输入格式:**
输入一个整数n
输出格式:
**输出格式:**
最少带几张。
样例输入1:
**样例输入1:**
```
json
50
样例输出1:
```
**样例输出1:**
```
json
1
约定:
```
**约定:**
```
json
1
<=n<=
100
```
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <iostream>
using
namespace
std
;
int
solve
(
int
tar
,
int
*
meta
,
int
metan
,
int
*
seed
=
NULL
,
int
seedn
=
0
)
{
if
(
tar
==
0
)
{
return
seedn
;
}
int
min
=
-
1
;
int
m
;
int
*
seed1
=
new
int
[
seedn
+
1
];
if
(
seed
)
memcpy
(
seed1
,
seed
,
sizeof
(
int
)
*
seedn
);
for
(
int
i
=
0
;
i
<
metan
;
i
++
)
{
if
(
meta
[
i
]
<=
tar
)
{
seed1
[
seedn
]
=
meta
[
i
];
_____________________
;
if
(
m
!=
-
1
&&
(
min
==
-
1
||
min
>
m
))
min
=
m
;
break
;
}
}
delete
[]
seed1
;
return
min
;
}
int
main
()
{
int
arr
[]
=
{
100
,
50
,
20
,
10
,
5
,
1
};
int
n
=
6
;
int
total
;
cin
>>
total
;
int
result
=
solve
(
total
,
arr
,
n
);
cout
<<
result
<<
endl
;
return
0
;
}
```
## template
...
...
@@ -58,7 +117,7 @@ int main()
## 答案
```
cpp
m
=
solve
(
tar
-
meta
[
i
],
meta
,
metan
,
seed1
,
seedn
+
1
);
```
## 选项
...
...
@@ -66,17 +125,17 @@ int main()
### A
```
cpp
m
=
solve
(
tar
-
meta
[
i
],
meta
,
metan
,
seed1
,
seedn
);
```
### B
```
cpp
m
=
solve
(
tar
+
meta
[
i
],
meta
,
metan
,
seed1
,
seedn
);
```
### C
```
cpp
m
=
solve
(
tar
+
meta
[
i
],
meta
,
metan
,
seed1
,
seedn
+
1
);
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/2.exercises/solution.md
浏览文件 @
4f66165b
# 数字归类
题目描述
**题目描述**
一个数里面若含有数字1,则归类到1字类,含有数字2,则归类到2字类,所以一个数可能同时归类到不同的数字类。对于0、1、2、3、4、5、6、7、8、9这十个数字类,因研究需要,急于想知道某一堆数中,究竟归类到这些数字类的个数。
样例输入
**样例输入**
```
json
123
456
175
2
61
9998
12
5053
382
样例输出
```
**样例输出**
```
json
0
:
1
1
:
4
2
:
4
...
...
@@ -15,9 +23,41 @@
7
:
1
8
:
2
9
:
1
```
提示
注意:输出结果中冒号后面有空格
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
#include <string.h>
int
result
[
10
];
int
main
(
void
)
{
memset
(
result
,
0
,
sizeof
(
int
)
*
10
);
int
n
;
int
arr
[
10
];
while
(
scanf
(
"%d"
,
&
n
)
!=
EOF
)
{
memset
(
arr
,
0
,
sizeof
(
int
)
*
10
);
if
(
n
==
0
)
arr
[
0
]
=
1
;
while
(
n
>
0
)
{
____________
;
}
for
(
int
i
=
0
;
i
<
10
;
i
++
)
result
[
i
]
+=
arr
[
i
];
}
for
(
int
i
=
0
;
i
<
10
;
i
++
)
printf
(
"%d: %d
\n
"
,
i
,
result
[
i
]);
return
0
;
}
```
## template
```
cpp
...
...
@@ -36,7 +76,8 @@ int main(void)
arr
[
0
]
=
1
;
while
(
n
>
0
)
{
____________
arr
[
n
%
10
]
=
1
;
n
=
n
/
10
;
}
for
(
int
i
=
0
;
i
<
10
;
i
++
)
result
[
i
]
+=
arr
[
i
];
...
...
data/2.dailycode中阶/1.cpp/3.exercises/solution.md
浏览文件 @
4f66165b
# 利用字母组成图形
利用字母可以组成一些美丽的图形,下面给出了一个例子:
```
json
ABCDEFG
BABCDEF
CBABCDE
DCBABCD
EDCBABC
```
这是一个5行7列的图形,请找出这个图形的规律,并输出一个n行m列的图形。
输入一行,包含两个整数n和m,分别表示你要输出的图形的行数的列数。
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
#include <math.h>
int
main
()
{
int
m
,
n
;
scanf
(
"%d%d"
,
&
n
,
&
m
);
int
i
,
j
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
j
=
0
;
j
<
m
;
j
++
)
{
______________
;
}
printf
(
"
\n
"
);
}
return
0
;
}
```
## template
```
cpp
...
...
@@ -23,7 +50,7 @@ int main()
{
for
(
j
=
0
;
j
<
m
;
j
++
)
{
______________
printf
(
"%c"
,
65
+
abs
(
i
-
j
));
}
printf
(
"
\n
"
);
}
...
...
data/2.dailycode中阶/1.cpp/4.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -5,6 +5,31 @@
<p
style=
"text-align:center"
><img
alt=
""
src=
"https://img-ask.csdnimg.cn/upload/1624519041254.jpg"
/>
</p>
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
int
main
()
{
int
a
[
10
],
i
,
n
;
int
isfind
=
0
;
printf
(
"please set array values:"
);
for
(
i
=
0
;
i
<
10
;
i
++
)
scanf
(
"%d"
,
&
a
[
i
]);
printf
(
"please enter one num:"
);
scanf
(
"%d"
,
&
n
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
______________
;
}
if
(
isfind
)
printf
(
"
\n
"
);
else
printf
(
"not find
\n
"
);
return
0
;
}
```
## template
```
cpp
...
...
@@ -20,7 +45,11 @@ int main()
scanf
(
"%d"
,
&
n
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
______________
if
(
a
[
i
]
<
n
)
{
isfind
=
1
;
printf
(
"%d "
,
a
[
i
]);
}
}
if
(
isfind
)
printf
(
"
\n
"
);
...
...
data/2.dailycode中阶/1.cpp/5.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -15,6 +15,40 @@
<pre>
<code>
9,1,1
</code></pre>
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
int
main
()
{
int
a
[
6
][
6
];
int
m
,
n
;
int
i
,
j
;
int
max
;
int
indexx
=
0
,
indexy
=
0
;
scanf
(
"%d %d"
,
&
m
,
&
n
);
for
(
i
=
0
;
i
<
m
;
i
++
)
{
for
(
j
=
0
;
j
<
n
;
j
++
)
{
scanf
(
"%d"
,
&
a
[
i
][
j
]);
if
(
i
==
0
&&
j
==
0
)
{
max
=
a
[
i
][
j
];
indexx
=
0
;
indexy
=
0
;
}
else
{
_____________
;
}
}
}
printf
(
"%d,%d,%d
\n
"
,
max
,
indexx
,
indexy
);
return
0
;
}
```
## template
```
cpp
...
...
@@ -40,7 +74,12 @@ int main()
}
else
{
_____________
if
(
a
[
i
][
j
]
>
max
)
{
max
=
a
[
i
][
j
];
indexx
=
i
;
indexy
=
j
;
}
}
}
}
...
...
data/2.dailycode中阶/1.cpp/6.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -2,8 +2,39 @@
已知一个浮点数A(0<A<5),求它由哪两个整数B/C相除的值最接近,有相同值时要求B最小
例如:
```
json
A=
0.2
B=
1
C=
5
```
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <stdio.h>
#include <math.h>
int
main
()
{
float
A
=
0.2
f
;
int
x
=
0
;
if
(
A
<
0
)
{
x
=
1
;
A
=
1
/
A
;
}
float
delta
=
1
;
int
B
=
1
,
C
=
1
;
do
{
____________
;
}
while
(
delta
>
0.000001
);
if
(
x
==
0
)
printf
(
"%d / %d"
,
C
,
B
-
1
);
else
printf
(
"%d / %d"
,
B
-
1
,
C
);
return
0
;
}
```
## template
...
...
@@ -23,7 +54,9 @@ int main()
int
B
=
1
,
C
=
1
;
do
{
____________
C
=
(
int
)(
B
*
A
);
delta
=
fabs
(
C
/
(
float
)
B
-
A
);
B
++
;
}
while
(
delta
>
0.000001
);
if
(
x
==
0
)
printf
(
"%d / %d"
,
C
,
B
-
1
);
...
...
data/2.dailycode中阶/1.cpp/7.exercises/solution.md
浏览文件 @
4f66165b
# 矩阵问题
题目描述
**题目描述**
编写以下函数:
(1)在一个二维数组中形成以下形式的n阶矩阵:
```
json
[
1
1
1
1
1
2
1
1
1
1
3
2
1
1
1
4
3
2
1
1
5
4
3
2
1
]
```
```
json
[
1
1
1
1
1
2
1
1
1
1
3
2
1
1
1
4
3
2
1
1
5
4
3
2
1
]
```
(2)去掉靠边的元素,生成新的n-2阶矩阵;
(3)求生成的n阶矩阵主对角线上的元素之和;
(4)以方阵形式输出数组。
在main函数中调用以上函数进行测试。
输入
**输入**
输入生成矩阵的阶数(n>=2)
输出
**输出**
以方阵形式输出生成的n阶矩阵、去掉靠边的元素生成的新的n-2阶矩阵、以及生成的n阶矩阵主对角线上的元素之和,最后一行要回车
样例输入
**样例输入**
```
json
5
样例输出
Generated matrix:
```
**样例输出**
```
json
Generated
matrix:
1
1
1
1
1
2
1
1
1
1
3
2
1
1
1
4
3
2
1
1
5
4
3
2
1
```
del
the
elements
on
the
side:
```
json
1
1
1
2
1
1
3
2
1
```
The
sum
of
the
diagonal:
5
```
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <iostream>
using
namespace
std
;
int
main
()
{
while
(
1
)
{
int
a
;
cin
>>
a
;
int
array
[
a
][
a
];
for
(
int
i
=
0
;
i
<
a
;
i
++
)
for
(
int
j
=
0
;
j
<
a
;
j
++
)
{
if
(
j
<
i
)
array
[
i
][
j
]
=
i
+
1
-
j
;
else
array
[
i
][
j
]
=
1
;
}
cout
<<
"Generated matrix:"
<<
endl
;
for
(
int
i
=
0
;
i
<
a
;
i
++
)
{
for
(
int
j
=
0
;
j
<
a
;
j
++
)
{
cout
<<
array
[
i
][
j
];
}
cout
<<
endl
;
}
cout
<<
"del the elements on the side:"
<<
endl
;
for
(
int
i
=
1
;
i
<
a
-
1
;
i
++
)
{
________________
;
cout
<<
endl
;
}
int
sum
=
0
;
int
i
,
j
;
for
(
i
=
a
-
2
,
j
=
1
;
i
>=
1
;
i
--
,
j
++
)
{
sum
+=
array
[
i
][
j
];
}
cout
<<
"The sum of the diagonal:"
<<
sum
<<
endl
;
}
return
0
;
}
```
## template
...
...
@@ -96,7 +156,10 @@ int main()
## 答案
```
cpp
for
(
int
j
=
1
;
j
<
a
-
1
;
j
++
)
{
cout
<<
array
[
i
][
j
];
}
```
## 选项
...
...
@@ -104,17 +167,26 @@ int main()
### A
```
cpp
for
(
int
j
=
1
;
j
<
a
-
1
;
j
++
)
{
cout
<<
array
[
i
-
1
][
j
-
1
];
}
```
### B
```
cpp
for
(
int
j
=
1
;
j
<
a
-
1
;
j
++
)
{
cout
<<
array
[
i
+
1
][
j
+
1
];
}
```
### C
```
cpp
for
(
int
j
=
0
;
j
<
a
;
j
++
)
{
cout
<<
array
[
i
][
j
];
}
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/8.exercises/solution.md
浏览文件 @
4f66165b
# 偶数 or 奇数
偶数 or 奇数
时间限制: 1 Sec 内存限制: 128 MB
题目描述
**题目描述**
编程班老师搞了一个有 N (1 <= N <= 100) 个正整数 I (1 <= I <= 10^60) 的表,叫 同学们去统计每个数里面数字(0,1,2,3,4,5,6,7,8,9)(注 0 为偶数)的奇偶数 字个数。写一个程序读入 N 个整数,统计每个整数的数字奇偶个数。
输入
**输入**
第 1 行: 一个单独的整数: N
第 2 到第 N+1 行: 每行一个长长(小于等于 60 位)的整数,需要统计数字奇偶个数。
输出
1.
.N 行: 第 j 行根据第 j 个整数输出奇数个数与偶数个数。
样例输入
**输出**
1.
.N 行: 第 j 行根据第 j 个整数输出奇数个数与偶数个数。
**样例输入**
```
json
2
1024
5931
样例输出
```
**样例输出**
```
json
1
3
4
0
```
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <iostream>
#include <string>
using
namespace
std
;
string
a
[
105
];
int
b
[
105
],
c
[
105
];
int
qiujishu
(
string
x
)
{
int
jishu
=
0
;
for
(
int
i
=
0
;
x
.
c_str
()[
i
];
i
++
)
{
(
1
)
____________
;
}
return
jishu
;
}
int
qiuoushu
(
string
x
)
{
int
oushu
=
0
;
for
(
int
i
=
0
;
x
.
c_str
()[
i
];
i
++
)
{
(
2
)
____________
;
}
return
oushu
;
}
int
main
()
{
int
n
;
cin
>>
n
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
cin
>>
a
[
i
];
b
[
i
]
=
qiujishu
(
a
[
i
]);
c
[
i
]
=
qiuoushu
(
a
[
i
]);
}
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
cout
<<
b
[
i
]
<<
" "
<<
c
[
i
]
<<
endl
;
}
return
0
;
}
```
## template
```
cpp
#include<iostream>
#include<string>
#include
<iostream>
#include
<string>
using
namespace
std
;
string
a
[
105
];
int
b
[
105
],
c
[
105
];
int
qiujishu
(
string
x
){
int
jishu
=
0
;
for
(
int
i
=
0
;
x
.
c_str
()[
i
];
i
++
){
if
((
x
.
c_str
()[
i
]
-
'0'
)
%
2
==
1
)
jishu
++
;
int
b
[
105
],
c
[
105
];
int
qiujishu
(
string
x
)
{
int
jishu
=
0
;
for
(
int
i
=
0
;
x
.
c_str
()[
i
];
i
++
)
{
if
((
x
.
c_str
()[
i
]
-
'0'
)
%
2
==
1
)
jishu
++
;
}
return
jishu
;
}
int
qiuoushu
(
string
x
){
int
oushu
=
0
;
for
(
int
i
=
0
;
x
.
c_str
()[
i
];
i
++
){
if
((
x
.
c_str
()[
i
]
-
'0'
)
%
2
==
0
)
oushu
++
;
int
qiuoushu
(
string
x
)
{
int
oushu
=
0
;
for
(
int
i
=
0
;
x
.
c_str
()[
i
];
i
++
)
{
if
((
x
.
c_str
()[
i
]
-
'0'
)
%
2
==
0
)
oushu
++
;
}
return
oushu
;
}
int
main
()
{
int
n
;
cin
>>
n
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
){
cin
>>
a
[
i
];
b
[
i
]
=
qiujishu
(
a
[
i
]);
c
[
i
]
=
qiuoushu
(
a
[
i
]);
cin
>>
n
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
cin
>>
a
[
i
];
b
[
i
]
=
qiujishu
(
a
[
i
]);
c
[
i
]
=
qiuoushu
(
a
[
i
]);
}
for
(
int
i
=
1
;
i
<=
n
;
i
++
){
cout
<<
b
[
i
]
<<
" "
<<
c
[
i
]
<<
endl
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
cout
<<
b
[
i
]
<<
" "
<<
c
[
i
]
<<
endl
;
}
return
0
;
}
...
...
@@ -58,7 +122,12 @@ int main()
## 答案
```
cpp
(
1
)
if
((
x
.
c_str
()[
i
]
-
'0'
)
%
2
==
1
)
jishu
++
;
(
2
)
if
((
x
.
c_str
()[
i
]
-
'0'
)
%
2
==
0
)
oushu
++
;
```
## 选项
...
...
@@ -66,17 +135,32 @@ int main()
### A
```
cpp
(
1
)
if
((
x
.
c_str
()[
i
])
%
2
==
1
)
jishu
++
;
(
2
)
if
((
x
.
c_str
()[
i
])
%
2
==
0
)
oushu
++
;
```
### B
```
cpp
(
1
)
if
((
x
.
c_str
()[
i
])
%
2
==
0
)
jishu
++
;
(
2
)
if
((
x
.
c_str
()[
i
])
%
2
==
1
)
oushu
++
;
```
### C
```
cpp
(
1
)
if
((
x
.
c_str
()[
i
])
/
2
==
1
)
jishu
++
;
(
2
)
if
((
x
.
c_str
()[
i
])
/
2
==
0
)
oushu
++
;
```
\ No newline at end of file
data/2.dailycode中阶/1.cpp/9.exercises/solution.md
浏览文件 @
4f66165b
...
...
@@ -19,6 +19,32 @@
<pre>
B 252
</pre>
以下程序实现了这一功能,请你填补空白处内容:
```
cpp
#include <iostream>
using
namespace
std
;
int
main
()
{
double
n
,
A
,
B
;
cin
>>
n
;
B
=
12
*
0.7
*
n
;
if
(
n
<=
10
)
{
A
=
10
*
n
;
}
else
if
(
n
>
10
&&
n
<=
20
)
{
A
=
10
*
10
+
(
n
-
10
)
*
8.2
;
}
___________________________
;
if
(
A
<
B
)
{
cout
<<
"A "
<<
A
;
}
else
{
cout
<<
"B "
<<
B
;
}
return
0
;
}
```
## template
```
cpp
...
...
@@ -50,7 +76,9 @@ int main() {
## 答案
```
cpp
else
{
A
=
10
*
8.2
+
(
n
-
20
)
*
7.5
+
10
*
10
;
}
```
## 选项
...
...
@@ -58,17 +86,23 @@ int main() {
### A
```
cpp
else
{
A
=
20
*
7.5
;
}
```
### B
```
cpp
else
{
A
=
(
n
-
10
)
*
8.2
+
(
n
-
20
)
*
7.5
+
10
*
10
;
}
```
### C
```
cpp
else
{
A
=
(
n
-
10
)
*
8.2
+
(
n
-
20
)
*
7.5
;
}
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录