解题思路:先找最大最小值,在找出最大最小值位置,根据不同情况换位加斩,直接抬走
注意事项:无
参考代码:
#include "stdio.h"
int main()
{
int x[10], y[10], k = 0, z[10], g = 0;
int q, w;
for (int j = 0; j < 10; j++)
scanf("%d", &x[j]);
for (int j = 0; j < 10; j++)
y[k++] = x[j];
for (int j = 0; j < 10; j++)
z[g++] = x[j];
for (int v = 0; v < 9; v++)
{
if (x[v] > x[v + 1])
{
q = x[v];
x[v] = x[v + 1];
x[v + 1] = q;
}
}
for (int v = 0; v < 9; v++)
{
if (y[v] < y[v + 1])
{
w = y[v];
y[v] = y[v + 1];
y[v + 1] = w;
}
}
int m, n;
for (int s = 0; s < 10; s++)
{
if (x[9] == z[s])
m = s;//大
if (y[9] == z[s])
n = s;//小
}
if (m != 0 && n != 9)
{
int qq, ww;
qq = z[0];
z[0] = z[n];
z[n] = qq;
ww = z[9];
z[9] = z[m];
z[m] = ww;
for (int ss = 0; ss < 10; ss++)
printf("%d ", z[ss]);
return 0;
}
if (m == 0 && n == 9)
{
int j;
j = z[0];
z[0] = z[9];
z[9] = j;
for (int fd = 0; fd < 10; fd++)
printf("%d ", z[fd]);
return 0;
}
if (m == 0 && n != 9);//m大.n小
{
int aa, bb;
aa = z[0];
z[0] = z[9];
z[9] = aa;
bb = z[n];
z[n] = z[0];
z[0] = bb;
for (int gh = 0; gh < 10; gh++)
printf("%d ", z[gh]);
return 0;
}
if (m != 0 && n == 9);
{
int kk, vv;
kk = z[9];
z[9] = z[0];
z[0] = kk;
vv = z[m];
z[m] = z[9];
z[9] = vv;
for (int pp = 0; pp < 10; pp++)
printf("%d ", z[pp]);
}
}
0.0分
1 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复