题解 AT4170 【[ABC103A] Task Scheduling Problem】

翻译

\(3\) 个正整数 \(a\)\(b\)\(c\),请你输出这 \(3\) 个数中的最大值 \(-\) 最小值的差。

分析

求最大值 \(-\) 最小值的差,我们自然可以使用 for 循环进行判断,但在这里介绍一种新方法,C++ 中的 max 函数与 min 函数,它的格式如下:

cout<<min(a,b);
cout<<max(a,b);

知道它的格式以后,不难写出程序。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<abs(max(a,max(b,c))-min(a,min(b,c)));
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tearing/p/12371548.html