ILIKEYSH1314 @ 2024-12-22 12:54:56
#include<bits/stdc++.h>
using namespace std;
int a[5201314];
int main(){
int n,k;
int maxx,minn;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
maxx = max(maxx, a[i]);
minn = min(minn, a[i]);
}
for(int j=0;j<n;j++){
if(a[j]<minn){
minn=a[j];
}
else if(a[j]>minn){
maxx=a[j];
}
}
for(int x=0;x<n;x++){
if(a[x]<k){
a[x]=minn;
}
else if(a[x]>k){
a[x]=maxx;
}
else if(a[x]==k){
a[x]=k;
}
}
for(int d=0;d<n;d++){
cout<<a[d]<<" ";
}
return 0;
}
by lzoyvce @ 2024-12-22 13:18:23
码太乱了 整理一下
#include<bits/stdc++.h>
using namespace std;
int a[5201314];
int main(){
int n,k;
int maxx,minn;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
maxx = max(maxx, a[i]);
minn = min(minn, a[i]);
}
for(int i=0;i<n;i++){
if(a[i]<minn){
minn=a[i];
}
else if(a[i]>minn){
maxx=a[i];
}
}
for(int i=0;i<n;i++){
if(a[i]<k){
a[i]=minn;
}
else if(a[i]>k){
a[i]=maxx;
}
else if(a[x]==k){
a[i]=k;
}
}
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
return 0;
}
by lzoyvce @ 2024-12-22 13:22:31
瞎猫碰到死耗子awa
绕着绕着把自己绕晕了
有代码证明:
《else if(a[i]>minn{maxx=a[i];}》
《maxx和minn,傻傻分不清》
建议0分+回卢重造 qwq
by Tenko_awa @ 2024-12-24 21:16:37
else if(a[x]==k){ a[i]=k; } 可以不要
by Tenko_awa @ 2024-12-24 21:21:34
@lzoyvce
else if(a[i]>k)
a[i]=maxx;
else if(a[x]==k)
a[i]=k;
你给他整理成什么了 一个x一个y
by Tenko_awa @ 2024-12-24 21:35:10
这道题其实是比较简单的,瞅瞅题解大概就会了
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n, k, Min = 1, Max = -1;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
Min = min(Min, a[i]);
Max = max(Max, a[i]);
}
for (int i = 1; i <= n; i++) {
if (a[i] < k) a[i] = Min;
if (a[i] > k) a[i] = Max;
cout << a[i] << ' ';
}
return 0;
}