Problem A: 编写函数:三个数的最大最小值 (Append Code)

Problem A: 编写函数:三个数的最大最小值 (Append Code)

Time Limit: 1 Sec   Memory Limit: 2 MB
Submit: 6956   Solved: 4558
[ Submit][ Status][ Web Board]

Description

给出三个数a,b,c,最大值是?最小值是?

-----------------------------------------------------------------------------

编写以下两个函数:

get_num()的功能是读取输入的三个整数a,b,c;

max_min()的功能是求出a,b,c的最大值和最小值。

以上函数的调用格式见“Append Code”。这里不给出函数原型,请通过main()函数自行确定。

Input

输入的第一个整数n,表示有n组测试数据,每组3个整数:a,b,c。a,b,c都在int类型范围内。

Output

每组测试数据对应输出一行:为a,b,c的最大值和最小值,格式见sample。

Sample Input

520 15 1010 15 20100 100 00 1 -10 0 0

Sample Output

case 1 : 20, 10case 2 : 20, 10case 3 : 100, 0case 4 : 1, -1case 5 : 0, 0

HINT

Append Code

[ Submit][ Status][ Web Board]
한국어<   中文  فارسی  English  ไทย
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011 HUSTOJ Project TEAM

Anything about the Problems, Please Contact Admin:admin

#include <iostream>
#include <iomanip>
using namespace std;
 
int get_num(int &a,int &b,int &c)
{
    cin >> a>>b>>c;
}
int max_min(int &mmax,int &mmin,int &a,int &b,int &c)
{
        int t;
         if(a<b)
      {   t = a;
          a = b;
          b = t;
      }
      if(a<c)
      {
          t = a;
          a = c;
          c = t;
      }
      if(b<c)
      {
          t = b;
          b = c;
          c = t;
      }
      mmax = a;
      mmin = c;
    }
int main()
{
    int cases;
    int mmax, mmin, a, b, c;
 
    cin>>cases;
    for(int i = 1; i <= cases; ++i)
    {
        get_num(a, b, c);
        max_min(mmax, mmin, a, b, c);
        cout<<"case "<<i<<" : "<<mmax<<", "<<mmin<<endl;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值