top1编程
← 返回题目
题解

【入门】 四个人从高到低排队

2 条题解

  • 0
    @ 2026-7-29 20:23:50
    #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 << &#39; &#39; << b << &#39; &#39; << c << &#39; &#39; << d;
    	return 0; 
    }
    
    • 0
      @ 2026-7-29 0:17:04
      #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