题解
【入门】 四个人从高到低排队
2 条题解
-
0
#include <bits/stdc++.h> using namespace std; int main(){ int a, b, c, d; cin >> a >> b >> c >> d; if (a < b) { swap(a, b); } if (a < c) { swap(a, c); } if (a < d) { swap(a, d); } if (b < c) { swap(b, c); } if (b < d) { swap(b, d); } if (c < d) { swap(c, d); } cout << a << ' ' << b << ' ' << c << ' ' << d; return 0; } -
0
#include <iostream> #include <algorithm> using namespace std; int main() { int heights[4]; // 读入四个身高 for (int i = 0; i < 4; i++) { cin >> heights[i]; } // 降序排序 sort(heights, heights + 4, greater<int>()); // 输出 for (int i = 0; i < 4; i++) { cout << heights[i]; if (i < 3) cout << " "; } cout << endl; return 0; }
- 1