mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-23 09:38:42 +00:00
【实践课外】7.数组1
This commit is contained in:
parent
448707b424
commit
3040899e0f
32
【实践课外】7.数组1/7-12 数组-值钱的微信号.c
Normal file
32
【实践课外】7.数组1/7-12 数组-值钱的微信号.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int n, k, a[55], ans;
|
||||
|
||||
int main() {
|
||||
scanf("%d%d", &k, &n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
scanf("%d", &a[i]);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 2; j <= n; j++) {
|
||||
if (a[j] < a[j - 1]) {
|
||||
int t = a[j];
|
||||
a[j] = a[j - 1];
|
||||
a[j - 1] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (k > a[i]) {
|
||||
k -= a[i];
|
||||
ans++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\n", ans);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课外】7.数组1/7-12 数组-值钱的微信号.jpg
Normal file
BIN
【实践课外】7.数组1/7-12 数组-值钱的微信号.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 509 KiB |
40
【实践课外】7.数组1/7-14 数组-吹泡泡.c
Normal file
40
【实践课外】7.数组1/7-14 数组-吹泡泡.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
|
||||
const double PI = 3.14;
|
||||
const double FDT = 1.33;
|
||||
|
||||
int n, id[1005];
|
||||
double v[1005];
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
double r;
|
||||
|
||||
scanf("%lf", &r);
|
||||
|
||||
v[i] = FDT * PI * r * r * r;
|
||||
id[i] = i;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 2; j <= n; j++) {
|
||||
if (v[j] > v[j - 1] || (v[j] == v[j - 1] && id[j] < id[j - 1])) {
|
||||
double t = v[j];
|
||||
v[j] = v[j - 1];
|
||||
v[j - 1] = t;
|
||||
|
||||
int tt = id[j];
|
||||
id[j] = id[j - 1];
|
||||
id[j - 1] = tt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
printf("%.2lf %d\n", v[i], id[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课外】7.数组1/7-14 数组-吹泡泡.jpg
Normal file
BIN
【实践课外】7.数组1/7-14 数组-吹泡泡.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 415 KiB |
27
【实践课外】7.数组1/7-19 数组-数学鬼才.c
Normal file
27
【实践课外】7.数组1/7-19 数组-数学鬼才.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int q;
|
||||
|
||||
scanf("%d", &q);
|
||||
|
||||
while (q--) {
|
||||
long long n;
|
||||
|
||||
scanf("%lld", &n);
|
||||
|
||||
if (n >= 2018) {
|
||||
printf("0\n");
|
||||
} else {
|
||||
int ans = 1;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
ans = (long long)ans * i % 2018;
|
||||
}
|
||||
|
||||
printf("%d\n", ans);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课外】7.数组1/7-19 数组-数学鬼才.jpg
Normal file
BIN
【实践课外】7.数组1/7-19 数组-数学鬼才.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 354 KiB |
31
【实践课外】7.数组1/7-5 计算最大值出现的次数.c
Normal file
31
【实践课外】7.数组1/7-5 计算最大值出现的次数.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int n, a[1005];
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
scanf("%d", &a[i]);
|
||||
}
|
||||
|
||||
int max = a[0];
|
||||
|
||||
for (int i = 2; i <= n; i++) {
|
||||
if (a[i] > max) {
|
||||
max = a[i];
|
||||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (a[i] == max) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d %d\n", max, count);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课外】7.数组1/7-5 计算最大值出现的次数.jpg
Normal file
BIN
【实践课外】7.数组1/7-5 计算最大值出现的次数.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 286 KiB |
54
【实践课外】7.数组1/7-6 求一批整数中出现最多的个位数字.c
Normal file
54
【实践课外】7.数组1/7-6 求一批整数中出现最多的个位数字.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int n, cnt[15];
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int x;
|
||||
|
||||
scanf("%d", &x);
|
||||
|
||||
if (x == 0) {
|
||||
cnt[0]++;
|
||||
} else {
|
||||
while (x) {
|
||||
cnt[x % 10]++;
|
||||
x /= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
|
||||
for (int i = 0; i <= 9; i++) {
|
||||
if (cnt[i] > max) {
|
||||
max = cnt[i];
|
||||
}
|
||||
}
|
||||
|
||||
int max_cnt = 0, out_cnt = 0;
|
||||
|
||||
for (int i = 0; i <= 9; i++) {
|
||||
if (cnt[i] == max) {
|
||||
max_cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d: ", max);
|
||||
|
||||
for (int i = 0; i <= 9; i++) {
|
||||
if (cnt[i] == max) {
|
||||
out_cnt++;
|
||||
|
||||
if (out_cnt < max_cnt) {
|
||||
printf("%d ", i);
|
||||
} else {
|
||||
printf("%d\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课外】7.数组1/7-6 求一批整数中出现最多的个位数字.jpg
Normal file
BIN
【实践课外】7.数组1/7-6 求一批整数中出现最多的个位数字.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 342 KiB |
27
【实践课外】7.数组1/7-7 装箱问题.c
Normal file
27
【实践课外】7.数组1/7-7 装箱问题.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int n, box[1005];
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int x;
|
||||
|
||||
scanf("%d", &x);
|
||||
|
||||
for (int j = 1; j <= n; j++) {
|
||||
if (box[j] + x <= 100) {
|
||||
printf("%d %d\n", x, j);
|
||||
box[j] += x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (box[n] == 0) n--;
|
||||
|
||||
printf("%d\n", n);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课外】7.数组1/7-7 装箱问题.jpg
Normal file
BIN
【实践课外】7.数组1/7-7 装箱问题.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 370 KiB |
Loading…
Reference in New Issue
Block a user