1
0
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:
Baoshuo Ren 2024-11-06 11:38:23 +08:00
parent 448707b424
commit 3040899e0f
Failed to extract signature
12 changed files with 211 additions and 0 deletions

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 KiB