3107. 数据交换

单点时限: 2.0 sec

内存限制: 256 MB

输入 n(1<n<11) 个整数,将其中最小数与第一个数交换,将其中最大数与最后一个数交换。

定义 3 个函数:

1) input 输入

2) process 处理交换

3) output 输出

//* Specification of input *

void input(int* p, int n);

/* PreCondition:

p points to an array with n integers

PostCondition:

enter and store n integers into an array pointed by p

*/

//* Specification of process *

void process(int* p, int n);

/* PreCondition:

p points to an array with n integers

PostCondition:

swap smallest number with the first number of an array pointed by p,

and swap largest number with the last number

*/

//* Specification of output *

void output(int* p, int n);

/* PreCondition:

p points to an array with n integers

PostCondition:

print each element of an array pointed by p in one line, with one blank between elements.

*/

只需按要求写出函数定义,并使用给定的测试程序测试你所定义函数的正确性。

不要改动测试程序。测试正确后,将测试程序和函数定义一起提交。

/*********/

/ /

/ DON'T MODIFY main function ANYWAY! /

/ /

/*********/

include

define N 10

//* Specification of input *

void input(int* p, int n)

/* PreCondition:

p points to an array with n integers

PostCondition:

enter and store n integers into an array pointed by p

*/

{ //TODO: your function definition

}

//* Specification of process *

void process(int* p, int n)

/* PreCondition:

p points to an array with n integers

PostCondition:

swap smallest number with the first number of an array pointed by p,

and swap largest number with the last number

*/

{ //TODO: your function definition

}

//* Specification of output *

void output(int* p, int n)

/* PreCondition:

p points to an array with n integers

PostCondition:

print each element of an array pointed by p in one line,

with one blank between elements.

*/

{ //TODO: your function definition

}

/*********/

int main()

{ int a[N],n;

scanf(“%d”,&n);

//* functions input, process, output are called here ***

input(a,n);

process(a,n);

output(a,n);

//************

return 0;

}

输入格式

-

输出格式

-

样例

Input
-
Output
-

334 人解决,373 人已尝试。

386 份提交通过,共有 1309 份提交。

2.0 EMB 奖励。

创建: 9 年前.

修改: 7 年,3 月前.

最后提交: 10 月前.

来源: N/A

题目标签