刷清橙OJ--A1029.补充函数

来源:互联网 发布:手机音乐转调软件 编辑:程序博客网 时间:2024/06/03 20:37
问题:
A1029. 补写函数
时间限制:1.0s   内存限制:512.0MB  
总提交次数:2606   AC次数:1201   平均分:47.10
问题描述
  根据主程序,补写函数,使得程序可以输出三个数的最大值和最小值。
输入格式
  输入包含四个数,前三个数为a,b,c,第四个数为一个调用函数的编号,如果第四个数为0,则调用第一个函数,否则调用第二个函数。
输出格式
  输出a,b,c的最大值和最小值。
样例输入
100 200 300 1
样例输出
300 100


这是一道完善程序的试题,你只需要在下面程序标注的"@你的代码"的位置补充适当的语句或语句段使程序能正确运行即可,在提交的时候,你要提交的内容只包括补充的内容,不包括其他的代码。
  1. @你的代码
  2. int main()
  3. {
  4.     int a, b, c, se, min, max;
  5.     cin >> a >> b >> c >> se;
  6.     if (se == 0)
  7.         maxmin_0(a, b, c, &max, &min);
  8.     else
  9.         maxmin_1(a, b, c, max, min);
  10.     cout << max << ' ' << min << endl;
  11. }

代码:

#include <iostream>#include <algorithm>using namespace std; void maxmin_1(int a,int b,int c,int &max,int &min) { int temp[4] = { a,b,c,0 }; sort(temp,temp + 3);//排序函数 max = temp[2]; min = temp[0]; } void maxmin_0(int a, int b, int c, int* max, int* min) { //所传参数为地址 int temp[4] = { a,b,c,0 }; sort(temp, temp + 3); *min = temp[0]; *max = temp[2]; }

个人想法:这个就是想到是传引用和传指针的区别。还是说看的别人的。在我的知识里收藏的那个并不能用。不知道哪里错了。