Topic description
Enter three integers, and output the values in descending order.
Requirements: Define a function with no return value. The function parameter is a reference to three integer parameters, such as int &a, int &b, int &c. Sort the three parameters by referencing the method within the function. The main function calls this function to sort.
Requirement: The three integers cannot be sorted directly, must be passed through a function and a method by reference.
enter
The first line of input t indicates that there are t test instances
From the second line, enter three integers per line
input line t
output
Each line outputs each instance in ascending order, with three integers separated by a single space
input example 1
3
2 4 6
88 99 77
111 333 222
2 4 6
88 99 77
111 333 222
output sample 1
6 4 2
99 88 77
333 222 111
99 88 77
333 222 111
Thought analysis
For such a simple problem, it is necessary to use a complex method to solve it, not even an array, directly on the three if, change.
code
#include<iostream>
using namespace std;
void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
void leibniz(int &a,int &b,int &c)
{
if(a<b)
swap(a,b);
if(a<c)
swap(a,c);
if(b<c)
swap(b,c);
}
int main()
{
int t,a,b,c;
cin>>t;
while(t--)
{
cin>>a>>b>>c;
leibniz(a,b,c);
cout<<a<<' '<<b<<' '<<c<<endl;
}
}