2 条题解

  • 0
    @ 2025-2-20 23:19:35

    C++代码

    #include <iostream>
    #include <iomanip> // 包含用于设置输出格式的头文件
    #include <vector>
    
    int main() {
        double H;
        int N;
        
        // 读取小明的身高和班上同学的数量
        std::cin >> H >> N;
        
        // 创建一个向量来存储每位同学与小明的身高差值
        std::vector<double> differences(N);
        for (int i = 0; i < N; ++i) {
            std::cin >> differences[i];
        }
        
        // 设置输出格式,保留两位小数
        std::cout << std::fixed << std::setprecision(2);
        
        // 输出小明的身高
        std::cout << H << " ";
        
        // 计算并输出每位同学的身高
        for (int i = 0; i < N; ++i) {
            double studentHeight = H + differences[i];
            std::cout << studentHeight << " ";
        }
        
        // 换行符,确保输出格式正确
        std::cout << std::endl;
        
        // 重置输出格式(可选,如果您希望后续输出不受影响)
        // std::cout.unsetf(std::ios::fixed);
        // std::cout.precision(6); // 默认精度通常是6,但具体取决于编译器和设置
        
        return 0;
    }
    
    • 0
      @ 2025-2-14 20:44:41

      Pascal :

      var a:array[1..100] of real;
          n,i:longint;
          h:real;
      begin
        readln(h,n);
        for i:=1 to n do read(a[i]);
        for i:=1 to n do
        if a[i]>=0 then a[i]:=h+a[i]
                   else a[i]:=h+a[i];
        write(h:0:2,' ');
        for i:=1 to n do write(a[i]:0:2,' ');
        end.
      
      
      
      • 1

      信息

      ID
      351
      时间
      1000ms
      内存
      128MiB
      难度
      10
      标签
      递交数
      2
      已通过
      1
      上传者