2024-06-22 23:31:01 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int digits[] = {5, 6, 2, 9, 4, 1};
|
|
|
|
int n = sizeof(digits)/sizeof(digits[0]);
|
|
|
|
|
|
|
|
// 对数组进行降序排序
|
|
|
|
sort(digits, digits+n, greater<int>());
|
|
|
|
|
|
|
|
// 构建最大三位数
|
|
|
|
int maxNum = digits[0]*100 + digits[1]*10 + digits[2];
|
|
|
|
cout << "The largest 3-digit number is: " << maxNum << endl;
|
|
|
|
return 0;
|
|
|
|
}
|