#include
#include
#include
int main() {
int n, k;
scanf("%d %d", &n, &k);
int* arr = (int*)malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int max = INT_MIN;
int min = INT_MAX;
for (int i = 0; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
if (arr[i] < min) {
min = arr[i];
}
}
for (int i = 0; i < n; i++) {
if (arr[i] > k) {
arr[i] = max;
} else if (arr[i] < k) {
arr[i] = min;
}
}
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
free(arr);
return 0;
}
#include
#include
int main() {
int n, k;
scanf("%d %d", &n, &k);
int* arr = (int*)malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int max = INT_MIN;
int min = INT_MAX;
for (int i = 0; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
if (arr[i] < min) {
min = arr[i];
}
}
for (int i = 0; i < n; i++) {
if (arr[i] > k) {
arr[i] = max;
} else if (arr[i] < k) {
arr[i] = min;
}
}
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
free(arr);
return 0;
}
全部评论
相关推荐
点赞 评论 收藏
分享